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>
39 #include <afs/assert.h>
42 #include "afs/afsint.h"
46 #include <afs/afssyscalls.h>
53 #include "viceinode.h"
54 #include "partition.h"
57 /* forward declarations */
58 void PurgeIndex_r(Volume * vp, VnodeClass class);
59 void PurgeHeader_r(Volume * vp);
62 VPurgeVolume_r(Error * ec, Volume * vp)
64 struct DiskPartition *tpartp = vp->partition;
65 char purgePath[MAXPATHLEN];
67 /* N.B. it's important here to use the partition pointed to by the
68 * volume header. This routine can, under some circumstances, be called
69 * when two volumes with the same id exist on different partitions.
71 (void)afs_snprintf(purgePath, sizeof purgePath, "%s/%s",
72 VPartitionPath(vp->partition),
73 VolumeExternalName(V_id(vp)));
74 PurgeIndex_r(vp, vLarge);
75 PurgeIndex_r(vp, vSmall);
79 * Call the fileserver to break all call backs for that volume
81 FSYNC_askfs(V_id(vp), tpartp->name, FSYNC_RESTOREVOLUME, 0);
85 VPurgeVolume(Error * ec, Volume * vp)
88 VPurgeVolume_r(ec, vp);
92 #define MAXOBLITATONCE 200
93 /* delete a portion of an index, adjusting offset appropriately. Returns 0 if
94 things work and we should be called again, 1 if success full and done, and -1
95 if an error occurred. It adjusts offset appropriately on 0 or 1 return codes,
96 and otherwise doesn't touch it */
98 ObliterateRegion(Volume * avp, VnodeClass aclass, StreamHandle_t * afile,
101 register struct VnodeClassInfo *vcp;
102 Inode inodes[MAXOBLITATONCE];
103 register afs_int32 iindex, nscanned;
105 char buf[SIZEOF_LARGEDISKVNODE];
108 register afs_int32 code;
109 register struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
112 vcp = &VnodeClassInfo[aclass];
113 offset = *aoffset; /* original offset */
116 /* advance over up to MAXOBLITATONCE inodes. nscanned tells us how many we examined.
117 * We remember the inodes in an array, and idec them after zeroing them in the index.
118 * The reason for these contortions is to make volume deletion idempotent, even
119 * if we crash in the middle of a delete operation. */
120 STREAM_SEEK(afile, offset, 0);
122 if (iindex >= MAXOBLITATONCE) {
125 code = STREAM_READ(vnode, vcp->diskSize, 1, afile);
127 offset += vcp->diskSize;
132 if (vnode->type != vNull) {
133 if (vnode->vnodeMagic != vcp->magic)
134 goto fail; /* something really wrong; let salvager take care of it */
135 if (VNDISK_GET_INO(vnode))
136 inodes[iindex++] = VNDISK_GET_INO(vnode);
140 /* next, obliterate the index and fflush (and fsync) it */
141 STREAM_SEEK(afile, *aoffset, 0); /* seek back to start of vnode index region */
142 memset(buf, 0, sizeof(buf)); /* zero out our proto-vnode */
143 for (i = 0; i < nscanned; i++) {
144 if (STREAM_WRITE(buf, vcp->diskSize, 1, afile) != 1)
147 STREAM_FLUSH(afile); /* ensure 0s are on the disk */
148 OS_SYNC(afile->str_fd);
150 /* finally, do the idec's */
151 for (i = 0; i < iindex; i++) {
152 IH_DEC(V_linkHandle(avp), inodes[i], V_parentId(avp));
156 /* return the new offset */
158 return hitEOF; /* return 1 if hit EOF (don't call again), otherwise 0 */
165 PurgeIndex(Volume * vp, VnodeClass class)
168 PurgeIndex_r(vp, class);
173 PurgeIndex_r(Volume * vp, VnodeClass class)
175 StreamHandle_t *ifile;
176 struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
178 register afs_int32 code;
182 fdP = IH_OPEN(vp->vnodeIndex[class].handle);
186 ifile = FDH_FDOPEN(fdP, "r+");
188 FDH_REALLYCLOSE(fdP);
192 offset = vcp->diskSize;
194 code = ObliterateRegion(vp, class, ifile, &offset);
196 break; /* if error or hit EOF */
203 PurgeHeader(Volume * vp)
211 PurgeHeader_r(Volume * vp)
213 IH_REALLYCLOSE(V_diskDataHandle(vp));
214 IH_DEC(V_linkHandle(vp), vp->vnodeIndex[vLarge].handle->ih_ino, V_id(vp));
215 IH_DEC(V_linkHandle(vp), vp->vnodeIndex[vSmall].handle->ih_ino, V_id(vp));
216 IH_DEC(V_linkHandle(vp), vp->diskDataHandle->ih_ino, V_id(vp));
218 /* And last, but not least, the link count table itself. */
219 IH_REALLYCLOSE(V_linkHandle(vp));
220 IH_DEC(V_linkHandle(vp), vp->linkHandle->ih_ino, V_parentId(vp));