2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
13 Institution: The Information Technology Center, Carnegie-Mellon University
16 #include <afsconfig.h>
17 #include <afs/param.h>
27 #include <sys/param.h>
33 #include <afs/assert.h>
36 #include "afs/afsint.h"
40 #include <afs/afssyscalls.h>
47 #include "viceinode.h"
48 #include "partition.h"
49 #include "daemon_com.h"
52 /* forward declarations */
53 static int ObliterateRegion(Volume * avp, VnodeClass aclass, StreamHandle_t * afile,
55 static void PurgeIndex(Volume * vp, VnodeClass class);
56 static void PurgeIndex_r(Volume * vp, VnodeClass class);
57 static void PurgeHeader_r(Volume * vp);
58 static void PurgeHeader(Volume * vp);
60 /* No lock needed. Only the volserver will call this, and only one transaction
61 * can have a given volume (volid/partition pair) in use at a time
64 VPurgeVolume(Error * ec, Volume * vp)
66 struct DiskPartition64 *tpartp = vp->partition;
67 char purgePath[MAXPATHLEN];
69 /* N.B. it's important here to use the partition pointed to by the
70 * volume header. This routine can, under some circumstances, be called
71 * when two volumes with the same id exist on different partitions.
73 (void)afs_snprintf(purgePath, sizeof purgePath, "%s/%s",
74 VPartitionPath(vp->partition),
75 VolumeExternalName(V_id(vp)));
76 PurgeIndex_r(vp, vLarge);
77 PurgeIndex_r(vp, vSmall);
81 * Call the fileserver to break all call backs for that volume
83 FSYNC_VolOp(V_id(vp), tpartp->name, FSYNC_VOL_BREAKCBKS, 0, NULL);
86 #define MAXOBLITATONCE 200
87 /* delete a portion of an index, adjusting offset appropriately. Returns 0 if
88 things work and we should be called again, 1 if success full and done, and -1
89 if an error occurred. It adjusts offset appropriately on 0 or 1 return codes,
90 and otherwise doesn't touch it */
92 ObliterateRegion(Volume * avp, VnodeClass aclass, StreamHandle_t * afile,
95 register struct VnodeClassInfo *vcp;
96 Inode inodes[MAXOBLITATONCE];
97 register afs_int32 iindex, nscanned;
99 char buf[SIZEOF_LARGEDISKVNODE];
102 register afs_int32 code;
103 register struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
106 vcp = &VnodeClassInfo[aclass];
107 offset = *aoffset; /* original offset */
110 /* advance over up to MAXOBLITATONCE inodes. nscanned tells us how many we examined.
111 * We remember the inodes in an array, and idec them after zeroing them in the index.
112 * The reason for these contortions is to make volume deletion idempotent, even
113 * if we crash in the middle of a delete operation. */
114 STREAM_SEEK(afile, offset, 0);
116 if (iindex >= MAXOBLITATONCE) {
119 code = STREAM_READ(vnode, vcp->diskSize, 1, afile);
121 offset += vcp->diskSize;
126 if (vnode->type != vNull) {
127 if (vnode->vnodeMagic != vcp->magic)
128 goto fail; /* something really wrong; let salvager take care of it */
129 if (VNDISK_GET_INO(vnode))
130 inodes[iindex++] = VNDISK_GET_INO(vnode);
134 /* next, obliterate the index and fflush (and fsync) it */
135 STREAM_SEEK(afile, *aoffset, 0); /* seek back to start of vnode index region */
136 memset(buf, 0, sizeof(buf)); /* zero out our proto-vnode */
137 for (i = 0; i < nscanned; i++) {
138 if (STREAM_WRITE(buf, vcp->diskSize, 1, afile) != 1)
141 STREAM_FLUSH(afile); /* ensure 0s are on the disk */
142 OS_SYNC(afile->str_fd);
144 /* finally, do the idec's */
145 for (i = 0; i < iindex; i++) {
146 IH_DEC(V_linkHandle(avp), inodes[i], V_parentId(avp));
150 /* return the new offset */
152 return hitEOF; /* return 1 if hit EOF (don't call again), otherwise 0 */
159 PurgeIndex(Volume * vp, VnodeClass class)
162 PurgeIndex_r(vp, class);
167 PurgeIndex_r(Volume * vp, VnodeClass class)
169 StreamHandle_t *ifile;
170 struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
172 register afs_int32 code;
176 fdP = IH_OPEN(vp->vnodeIndex[class].handle);
180 ifile = FDH_FDOPEN(fdP, "r+");
182 FDH_REALLYCLOSE(fdP);
186 offset = vcp->diskSize;
188 code = ObliterateRegion(vp, class, ifile, &offset);
190 break; /* if error or hit EOF */
197 PurgeHeader(Volume * vp)
205 PurgeHeader_r(Volume * vp)
207 IH_REALLYCLOSE(V_diskDataHandle(vp));
208 IH_DEC(V_linkHandle(vp), vp->vnodeIndex[vLarge].handle->ih_ino, V_id(vp));
209 IH_DEC(V_linkHandle(vp), vp->vnodeIndex[vSmall].handle->ih_ino, V_id(vp));
210 IH_DEC(V_linkHandle(vp), vp->diskDataHandle->ih_ino, V_id(vp));
212 /* And last, but not least, the link count table itself. */
213 IH_REALLYCLOSE(V_linkHandle(vp));
214 IH_DEC(V_linkHandle(vp), vp->linkHandle->ih_ino, V_parentId(vp));