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
10 #include <afsconfig.h>
11 #include <afs/param.h>
17 #include <sys/types.h>
24 #include <netinet/in.h>
41 #include <afs/afsint.h>
43 #include <afs/assert.h>
44 #include <afs/prs_fs.h>
49 #include <afs/cellconfig.h>
52 #include <afs/ihandle.h>
54 #include <afs/ntops.h>
56 #include <afs/vnode.h>
57 #include <afs/volume.h>
58 #include <afs/partition.h>
60 #include <afs/fssync.h>
62 #include "afs/audit.h"
68 #include <volser_prototypes.h>
71 extern struct volser_trans *FindTrans(), *NewTrans(), *TransList();
72 extern struct afsconf_dir *tdir;
73 extern char *volutil_PartitionName();
75 extern void LogError(afs_int32 errcode);
77 /* Forward declarations */
78 static int GetPartName(afs_int32 partid, char *pname);
80 #define OneDay (24*60*60)
86 afs_int32 localTid = 1;
87 afs_int32 VolPartitionInfo(), VolNukeVolume(), VolCreateVolume(),
88 VolDeleteVolume(), VolClone();
89 afs_int32 VolReClone(), VolTransCreate(), VolGetNthVolume(), VolGetFlags(),
90 VolForward(), VolDump();
91 afs_int32 VolForwardMultiple();
92 afs_int32 VolRestore(), VolEndTrans(), VolSetForwarding(), VolGetStatus(),
93 VolSetInfo(), VolGetName();
94 afs_int32 VolSignalRestore(), VolListPartitions(), VolListOneVolume(),
95 VolXListOneVolume(), VolXListVolumes();
96 afs_int32 VolListVolumes(), XVolListPartitions(), VolMonitor(),
97 VolSetIdsTypes(), VolSetDate(), VolSetFlags();
99 /* this call unlocks all of the partition locks we've set */
102 register struct DiskPartition *tp;
103 for (tp = DiskPartitionList; tp; tp = tp->next) {
104 if (tp->lock_fd != -1) {
105 close(tp->lock_fd); /* releases flock held on this partition */
112 /* get partition id from a name */
118 register int code = 0;
123 return -1; /* unknown */
125 /* otherwise check for vicepa or /vicepa, or just plain "a" */
127 if (!strncmp(aname, "/vicep", 6)) {
128 strncpy(ascii, aname + 6, 2);
130 return -1; /* bad partition name */
131 /* now partitions are named /vicepa ... /vicepz, /vicepaa, /vicepab, .../vicepzz, and are numbered
132 * from 0. Do the appropriate conversion */
134 /* one char name, 0..25 */
135 if (ascii[0] < 'a' || ascii[0] > 'z')
136 return -1; /* wrongo */
137 return ascii[0] - 'a';
139 /* two char name, 26 .. <whatever> */
140 if (ascii[0] < 'a' || ascii[0] > 'z')
141 return -1; /* wrongo */
142 if (ascii[1] < 'a' || ascii[1] > 'z')
143 return -1; /* just as bad */
144 code = (ascii[0] - 'a') * 26 + (ascii[1] - 'a') + 26;
145 if (code > VOLMAXPARTS)
152 ConvertVolume(avol, aname, asize)
159 /* It's better using the Generic VFORMAT since otherwise we have to make changes to too many places... The 14 char limitation in names hits us again in AIX; print in field of 9 digits (still 10 for the rest), right justified with 0 padding */
160 (void)afs_snprintf(aname, asize, VFORMAT, (unsigned long)avol);
165 ConvertPartition(apartno, aname, asize)
174 strcpy(aname, "/vicep");
176 aname[6] = 'a' + apartno;
180 aname[6] = 'a' + (apartno / 26);
181 aname[7] = 'a' + (apartno % 26);
187 /* the only attach function that takes a partition is "...ByName", so we use it */
189 XAttachVolume(error, avolid, apartid, amode)
195 char pbuf[30], vbuf[20];
196 register struct Volume *tv;
198 if (ConvertPartition(apartid, pbuf, sizeof(pbuf))) {
202 if (ConvertVolume(avolid, vbuf, sizeof(vbuf))) {
206 tv = VAttachVolumeByName(error, pbuf, vbuf, amode);
210 /* Adapted from the file server; create a root directory for this volume */
216 struct acl_accessList *ACL;
218 Inode inodeNumber, nearInode;
219 char buf[SIZEOF_LARGEDISKVNODE];
220 struct VnodeDiskObject *vnode = (struct VnodeDiskObject *)buf;
221 struct VnodeClassInfo *vcp = &VnodeClassInfo[vLarge];
227 memset(vnode, 0, SIZEOF_LARGEDISKVNODE);
229 V_pref(vp, nearInode);
231 IH_CREATE(V_linkHandle(vp), V_device(vp),
232 VPartitionPath(V_partition(vp)), nearInode, V_parentId(vp),
234 assert(VALID_INO(inodeNumber));
236 SetSalvageDirHandle(&dir, V_parentId(vp), vp->device, inodeNumber);
237 did.Volume = V_id(vp);
238 did.Vnode = (VnodeId) 1;
241 assert(!(MakeDir(&dir, &did, &did)));
242 DFlush(); /* flush all modified dir buffers out */
243 DZap(&dir); /* Remove all buffers for this dir */
244 length = Length(&dir); /* Remember size of this directory */
246 FidZap(&dir); /* Done with the dir handle obtained via SetSalvageDirHandle() */
248 /* build a single entry ACL that gives all rights to system:administrators */
249 /* this section of code assumes that access list format is not going to
252 ACL = VVnodeDiskACL(vnode);
253 ACL->size = sizeof(struct acl_accessList);
254 ACL->version = ACL_ACLVERSION;
258 ACL->entries[0].id = -204; /* this assumes System:administrators is group -204 */
259 ACL->entries[0].rights =
260 PRSFS_READ | PRSFS_WRITE | PRSFS_INSERT | PRSFS_LOOKUP | PRSFS_DELETE
261 | PRSFS_LOCK | PRSFS_ADMINISTER;
263 vnode->type = vDirectory;
265 vnode->modeBits = 0777;
266 vnode->linkCount = 2;
267 VNDISK_SET_LEN(vnode, length);
268 vnode->uniquifier = 1;
269 V_uniquifier(vp) = vnode->uniquifier + 1;
270 vnode->dataVersion = 1;
271 VNDISK_SET_INO(vnode, inodeNumber);
272 vnode->unixModifyTime = vnode->serverModifyTime = V_creationDate(vp);
276 vnode->vnodeMagic = vcp->magic;
278 IH_INIT(h, vp->device, V_parentId(vp),
279 vp->vnodeIndex[vLarge].handle->ih_ino);
282 code = FDH_SEEK(fdP, vnodeIndexOffset(vcp, 1), SEEK_SET);
284 code = FDH_WRITE(fdP, vnode, SIZEOF_LARGEDISKVNODE);
285 assert(code == SIZEOF_LARGEDISKVNODE);
286 FDH_REALLYCLOSE(fdP);
288 VNDISK_GET_LEN(length, vnode);
289 V_diskused(vp) = nBlocks(length);
295 SAFSVolPartitionInfo(acid, pname, partition)
296 struct rx_call *acid;
298 struct diskPartition *partition;
302 code = VolPartitionInfo(acid, pname, partition);
303 osi_auditU(acid, VS_ParInfEvent, code, AUD_STR, pname, AUD_END);
308 VolPartitionInfo(acid, pname, partition)
309 struct rx_call *acid;
311 struct diskPartition *partition;
313 register struct DiskPartition *dp;
316 if (!afsconf_SuperUser(tdir, acid, caller)) return VOLSERBAD_ACCESS;
319 dp = VGetPartition(pname, 0);
321 strncpy(partition->name, dp->name, 32);
322 strncpy(partition->devName, dp->devName, 32);
323 partition->lock_fd = dp->lock_fd;
324 partition->free = dp->free;
325 partition->minFree = dp->totalUsable;
328 return VOLSERILLEGAL_PARTITION;
331 /* obliterate a volume completely, and slowly. */
333 SAFSVolNukeVolume(acid, apartID, avolID)
334 struct rx_call *acid;
335 afs_int32 apartID, avolID;
339 code = VolNukeVolume(acid, apartID, avolID);
340 osi_auditU(acid, VS_NukVolEvent, code, AUD_LONG, avolID, AUD_END);
345 VolNukeVolume(acid, apartID, avolID)
346 struct rx_call *acid;
347 afs_int32 apartID, avolID;
352 register afs_int32 code;
354 char caller[MAXKTCNAMELEN];
356 /* check for access */
357 if (!afsconf_SuperUser(tdir, acid, caller))
358 return VOLSERBAD_ACCESS;
360 Log("%s is executing VolNukeVolume %u\n", caller, avolID);
362 tp = volutil_PartitionName(apartID);
365 strcpy(partName, tp); /* remember it for later */
366 /* we first try to attach the volume in update mode, so that the file
367 * server doesn't try to use it (and abort) while (or after) we delete it.
368 * If we don't get the volume, that's fine, too. We just won't put it back.
370 tvp = XAttachVolume(&error, avolID, apartID, V_VOLUPD);
371 code = nuke(partName, avolID);
373 VDetachVolume(&error, tvp);
377 /* create a new volume, with name aname, on the specified partition (1..n)
378 * and of type atype (readwriteVolume, readonlyVolume, backupVolume).
379 * As input, if *avolid is 0, we allocate a new volume id, otherwise we use *avolid
380 * for the volume id (useful for things like volume restore).
381 * Return the new volume id in *avolid.
384 SAFSVolCreateVolume(acid, apart, aname, atype, aparent, avolid, atrans)
385 struct rx_call *acid;
396 VolCreateVolume(acid, apart, aname, atype, aparent, avolid, atrans);
397 osi_auditU(acid, VS_CrVolEvent, code, AUD_LONG, *atrans, AUD_LONG,
398 *avolid, AUD_STR, aname, AUD_LONG, atype, AUD_LONG, aparent,
404 VolCreateVolume(acid, apart, aname, atype, aparent, avolid, atrans)
405 struct rx_call *acid;
415 afs_int32 junk; /* discardable error code */
416 register afs_int32 volumeID, doCreateRoot = 1;
417 register struct volser_trans *tt;
419 char caller[MAXKTCNAMELEN];
421 if (strlen(aname) > 31)
422 return VOLSERBADNAME;
423 if (!afsconf_SuperUser(tdir, acid, caller))
424 return VOLSERBAD_ACCESS;
426 Log("%s is executing CreateVolume '%s'\n", caller, aname);
427 if ((error = ConvertPartition(apart, ppath, sizeof(ppath))))
428 return error; /*a standard unix error */
429 if (atype != readwriteVolume && atype != readonlyVolume
430 && atype != backupVolume)
432 if ((volumeID = *avolid) == 0) {
434 Log("1 Volser: CreateVolume: missing volume number; %s volume not created\n", aname);
438 if ((aparent == volumeID) && (atype == readwriteVolume)) {
443 tt = NewTrans(volumeID, apart);
445 Log("1 createvolume: failed to create trans\n");
446 return VOLSERVOLBUSY; /* volume already busy! */
448 vp = VCreateVolume(&error, ppath, volumeID, aparent);
450 Log("1 Volser: CreateVolume: Unable to create the volume; aborted, error code %u\n", error);
455 V_uniquifier(vp) = 1;
456 V_creationDate(vp) = V_copyDate(vp);
457 V_inService(vp) = V_blessed(vp) = 1;
459 AssignVolumeName(&V_disk(vp), aname, 0);
462 V_destroyMe(vp) = DESTROY_ME;
464 V_maxquota(vp) = 5000; /* set a quota of 5000 at init time */
465 VUpdateVolume(&error, vp);
467 Log("1 Volser: create UpdateVolume failed, code %d\n", error);
470 VDetachVolume(&junk, vp); /* rather return the real error code */
475 strcpy(tt->lastProcName, "CreateVolume");
476 tt->rxCallPtr = acid;
477 Log("1 Volser: CreateVolume: volume %u (%s) created\n", volumeID, aname);
478 tt->rxCallPtr = (struct rx_call *)0;
480 return VOLSERTRELE_ERROR;
484 /* delete the volume associated with this transaction */
486 SAFSVolDeleteVolume(acid, atrans)
488 struct rx_call *acid;
492 code = VolDeleteVolume(acid, atrans);
493 osi_auditU(acid, VS_DelVolEvent, code, AUD_LONG, atrans, AUD_END);
498 VolDeleteVolume(acid, atrans)
500 struct rx_call *acid;
502 register struct volser_trans *tt;
504 char caller[MAXKTCNAMELEN];
506 if (!afsconf_SuperUser(tdir, acid, caller))
507 return VOLSERBAD_ACCESS;
508 tt = FindTrans(atrans);
511 if (tt->vflags & VTDeleted) {
512 Log("1 Volser: Delete: volume %u already deleted \n", tt->volid);
517 Log("%s is executing Delete Volume %u\n", caller, tt->volid);
518 strcpy(tt->lastProcName, "DeleteVolume");
519 tt->rxCallPtr = acid;
520 VPurgeVolume(&error, tt->volume); /* don't check error code, it is not set! */
521 tt->vflags |= VTDeleted; /* so we know not to do anything else to it */
522 tt->rxCallPtr = (struct rx_call *)0;
524 return VOLSERTRELE_ERROR;
526 Log("1 Volser: Delete: volume %u deleted \n", tt->volid);
527 return 0; /* vpurgevolume doesn't set an error code */
530 /* make a clone of the volume associated with atrans, possibly giving it a new
531 * number (allocate a new number if *newNumber==0, otherwise use *newNumber
532 * for the clone's id). The new clone is given the name newName. Finally, due to
533 * efficiency considerations, if purgeId is non-zero, we purge that volume when doing
534 * the clone operation. This may be useful when making new backup volumes, for instance
535 * since the net result of a clone and a purge generally leaves many inode ref counts
536 * the same, while doing them separately would result in far more iincs and idecs being
537 * peformed (and they are slow operations).
540 SAFSVolClone(acid, atrans, purgeId, newType, newName, newNumber)
541 struct rx_call *acid;
544 afs_int32 *newNumber;
545 afs_int32 purgeId; /* for efficiency reasons, sometimes faster to piggyback a purge here */
550 code = VolClone(acid, atrans, purgeId, newType, newName, newNumber);
551 osi_auditU(acid, VS_CloneEvent, code, AUD_LONG, atrans, AUD_LONG, purgeId,
552 AUD_STR, newName, AUD_LONG, newType, AUD_LONG, *newNumber,
558 VolClone(acid, atrans, purgeId, newType, newName, newNumber)
559 struct rx_call *acid;
562 afs_int32 *newNumber;
563 afs_int32 purgeId; /* for efficiency reasons, sometimes faster to piggyback a purge here */
567 register struct Volume *originalvp, *purgevp, *newvp;
569 register struct volser_trans *tt, *ttc;
570 char caller[MAXKTCNAMELEN];
572 if (strlen(newName) > 31)
573 return VOLSERBADNAME;
574 if (!afsconf_SuperUser(tdir, acid, caller))
575 return VOLSERBAD_ACCESS; /*not a super user */
577 Log("%s is executing Clone Volume new name=%s\n", caller, newName);
579 originalvp = (Volume *) 0;
580 purgevp = (Volume *) 0;
581 newvp = (Volume *) 0;
582 tt = ttc = (struct volser_trans *)0;
584 if (!newNumber || !*newNumber) {
585 Log("1 Volser: Clone: missing volume number for the clone; aborted\n");
590 if (newType != readonlyVolume && newType != backupVolume)
592 tt = FindTrans(atrans);
595 if (tt->vflags & VTDeleted) {
596 Log("1 Volser: Clone: volume %u has been deleted \n", tt->volid);
600 ttc = NewTrans(newId, tt->partition);
601 if (!ttc) { /* someone is messing with the clone already */
605 strcpy(tt->lastProcName, "Clone");
606 tt->rxCallPtr = acid;
610 purgevp = VAttachVolume(&error, purgeId, V_VOLUPD);
612 Log("1 Volser: Clone: Could not attach 'purge' volume %u; clone aborted\n", purgeId);
618 originalvp = tt->volume;
619 if ((V_type(originalvp) == backupVolume)
620 || (V_type(originalvp) == readonlyVolume)) {
621 Log("1 Volser: Clone: The volume to be cloned must be a read/write; aborted\n");
625 if ((V_destroyMe(originalvp) == DESTROY_ME) || !V_inService(originalvp)) {
626 Log("1 Volser: Clone: Volume %d is offline and cannot be cloned\n",
632 if (originalvp->device != purgevp->device) {
633 Log("1 Volser: Clone: Volumes %u and %u are on different devices\n", tt->volid, purgeId);
637 if (V_type(purgevp) != readonlyVolume) {
638 Log("1 Volser: Clone: The \"purge\" volume must be a read only volume; aborted\n");
642 if (V_type(originalvp) == readonlyVolume
643 && V_parentId(originalvp) != V_parentId(purgevp)) {
644 Log("1 Volser: Clone: Volume %u and volume %u were not cloned from the same parent volume; aborted\n", tt->volid, purgeId);
648 if (V_type(originalvp) == readwriteVolume
649 && tt->volid != V_parentId(purgevp)) {
650 Log("1 Volser: Clone: Volume %u was not originally cloned from volume %u; aborted\n", purgeId, tt->volid);
659 VCreateVolume(&error, originalvp->partition->name, newId,
660 V_parentId(originalvp));
662 Log("1 Volser: Clone: Couldn't create new volume; clone aborted\n");
663 newvp = (Volume *) 0;
666 if (newType == readonlyVolume)
667 V_cloneId(originalvp) = newId;
668 Log("1 Volser: Clone: Cloning volume %u to new volume %u\n", tt->volid,
671 Log("1 Volser: Clone: Purging old read only volume %u\n", purgeId);
672 CloneVolume(&error, originalvp, newvp, purgevp);
673 purgevp = NULL; /* clone releases it, maybe even if error */
675 Log("1 Volser: Clone: clone operation failed with code %u\n", error);
679 if (newType == readonlyVolume) {
680 AssignVolumeName(&V_disk(newvp), V_name(originalvp), ".readonly");
681 V_type(newvp) = readonlyVolume;
682 } else if (newType == backupVolume) {
683 AssignVolumeName(&V_disk(newvp), V_name(originalvp), ".backup");
684 V_type(newvp) = backupVolume;
685 V_backupId(originalvp) = newId;
687 strcpy(newvp->header->diskstuff.name, newName);
688 V_creationDate(newvp) = V_copyDate(newvp);
689 ClearVolumeStats(&V_disk(newvp));
690 V_destroyMe(newvp) = DESTROY_ME;
691 V_inService(newvp) = 0;
692 if (newType == backupVolume) {
693 V_backupDate(originalvp) = V_copyDate(newvp);
694 V_backupDate(newvp) = V_copyDate(newvp);
697 VUpdateVolume(&error, newvp);
699 Log("1 Volser: Clone: VUpdate failed code %u\n", error);
703 VDetachVolume(&error, newvp); /* allow file server to get it's hands on it */
705 VUpdateVolume(&error, originalvp);
707 Log("1 Volser: Clone: original update %u\n", error);
711 tt->rxCallPtr = (struct rx_call *)0;
713 tt = (struct volser_trans *)0;
714 error = VOLSERTRELE_ERROR;
722 VDetachVolume(&code, purgevp);
724 VDetachVolume(&code, newvp);
726 tt->rxCallPtr = (struct rx_call *)0;
734 /* reclone this volume into the specified id */
736 SAFSVolReClone(acid, atrans, cloneId)
737 struct rx_call *acid;
743 code = VolReClone(acid, atrans, cloneId);
744 osi_auditU(acid, VS_ReCloneEvent, code, AUD_LONG, atrans, AUD_LONG,
750 VolReClone(acid, atrans, cloneId)
751 struct rx_call *acid;
755 register struct Volume *originalvp, *clonevp;
758 register struct volser_trans *tt, *ttc;
759 char caller[MAXKTCNAMELEN];
761 /*not a super user */
762 if (!afsconf_SuperUser(tdir, acid, caller))
763 return VOLSERBAD_ACCESS;
765 Log("%s is executing Reclone Volume %u\n", caller, cloneId);
767 clonevp = originalvp = (Volume *) 0;
768 tt = (struct volser_trans *)0;
770 tt = FindTrans(atrans);
773 if (tt->vflags & VTDeleted) {
774 Log("1 Volser: VolReClone: volume %u has been deleted \n", tt->volid);
778 ttc = NewTrans(cloneId, tt->partition);
779 if (!ttc) { /* someone is messing with the clone already */
783 strcpy(tt->lastProcName, "ReClone");
784 tt->rxCallPtr = acid;
786 originalvp = tt->volume;
787 if ((V_type(originalvp) == backupVolume)
788 || (V_type(originalvp) == readonlyVolume)) {
789 Log("1 Volser: Clone: The volume to be cloned must be a read/write; aborted\n");
793 if ((V_destroyMe(originalvp) == DESTROY_ME) || !V_inService(originalvp)) {
794 Log("1 Volser: Clone: Volume %d is offline and cannot be cloned\n",
800 clonevp = VAttachVolume(&error, cloneId, V_VOLUPD);
802 Log("1 Volser: can't attach clone %d\n", cloneId);
806 newType = V_type(clonevp); /* type of the new volume */
808 if (originalvp->device != clonevp->device) {
809 Log("1 Volser: Clone: Volumes %u and %u are on different devices\n",
814 if (V_type(clonevp) != readonlyVolume && V_type(clonevp) != backupVolume) {
815 Log("1 Volser: Clone: The \"recloned\" volume must be a read only volume; aborted\n");
819 if (V_type(originalvp) == readonlyVolume
820 && V_parentId(originalvp) != V_parentId(clonevp)) {
821 Log("1 Volser: Clone: Volume %u and volume %u were not cloned from the same parent volume; aborted\n", tt->volid, cloneId);
825 if (V_type(originalvp) == readwriteVolume
826 && tt->volid != V_parentId(clonevp)) {
827 Log("1 Volser: Clone: Volume %u was not originally cloned from volume %u; aborted\n", cloneId, tt->volid);
833 Log("1 Volser: Clone: Recloning volume %u to volume %u\n", tt->volid,
835 CloneVolume(&error, originalvp, clonevp, clonevp);
837 Log("1 Volser: Clone: reclone operation failed with code %d\n",
843 /* fix up volume name and type, CloneVolume just propagated RW's */
844 if (newType == readonlyVolume) {
845 AssignVolumeName(&V_disk(clonevp), V_name(originalvp), ".readonly");
846 V_type(clonevp) = readonlyVolume;
847 } else if (newType == backupVolume) {
848 AssignVolumeName(&V_disk(clonevp), V_name(originalvp), ".backup");
849 V_type(clonevp) = backupVolume;
850 V_backupId(originalvp) = cloneId;
852 /* don't do strcpy onto diskstuff.name, it's still OK from 1st clone */
854 /* pretend recloned volume is a totally new instance */
855 V_copyDate(clonevp) = time(0);
856 V_creationDate(clonevp) = V_copyDate(clonevp);
857 ClearVolumeStats(&V_disk(clonevp));
858 V_destroyMe(clonevp) = 0;
859 V_inService(clonevp) = 0;
860 if (newType == backupVolume) {
861 V_backupDate(originalvp) = V_copyDate(clonevp);
862 V_backupDate(clonevp) = V_copyDate(clonevp);
864 V_inUse(clonevp) = 0;
865 VUpdateVolume(&error, clonevp);
867 Log("1 Volser: Clone: VUpdate failed code %u\n", error);
871 VDetachVolume(&error, clonevp); /* allow file server to get it's hands on it */
873 VUpdateVolume(&error, originalvp);
875 Log("1 Volser: Clone: original update %u\n", error);
879 tt->rxCallPtr = (struct rx_call *)0;
881 tt = (struct volser_trans *)0;
882 error = VOLSERTRELE_ERROR;
889 struct DiskPartition *tpartp = originalvp->partition;
890 FSYNC_askfs(cloneId, tpartp->name, FSYNC_RESTOREVOLUME, 0);
896 VDetachVolume(&code, clonevp);
898 tt->rxCallPtr = (struct rx_call *)0;
906 /* create a new transaction, associated with volume and partition. Type of
907 * volume transaction is spec'd by iflags. New trans id is returned in ttid.
908 * See volser.h for definition of iflags (the constants are named IT*).
911 SAFSVolTransCreate(acid, volume, partition, iflags, ttid)
912 struct rx_call *acid;
920 code = VolTransCreate(acid, volume, partition, iflags, ttid);
921 osi_auditU(acid, VS_TransCrEvent, code, AUD_LONG, *ttid, AUD_LONG, volume,
927 VolTransCreate(acid, volume, partition, iflags, ttid)
928 struct rx_call *acid;
934 register struct volser_trans *tt;
936 afs_int32 error, code;
938 char caller[MAXKTCNAMELEN];
940 if (!afsconf_SuperUser(tdir, acid, caller))
941 return VOLSERBAD_ACCESS; /*not a super user */
942 if (iflags & ITCreate)
944 else if (iflags & ITBusy)
946 else if (iflags & ITReadOnly)
948 else if (iflags & ITOffline)
951 Log("1 Volser: TransCreate: Could not create trans, error %u\n",
956 tt = NewTrans(volume, partition);
958 /* can't create a transaction? put the volume back */
959 Log("1 transcreate: can't create transaction\n");
960 return VOLSERVOLBUSY;
962 tv = XAttachVolume(&error, volume, partition, mode);
966 VDetachVolume(&code, tv);
974 strcpy(tt->lastProcName, "TransCreate");
976 return VOLSERTRELE_ERROR;
981 /* using aindex as a 0-based index, return the aindex'th volume on this server
982 * Both the volume number and partition number (one-based) are returned.
985 SAFSVolGetNthVolume(acid, aindex, avolume, apart)
986 struct rx_call *acid;
993 code = VolGetNthVolume(acid, aindex, avolume, apart);
994 osi_auditU(acid, VS_GetNVolEvent, code, AUD_LONG, *avolume, AUD_END);
999 VolGetNthVolume(acid, aindex, avolume, apart)
1000 struct rx_call *acid;
1005 Log("1 Volser: GetNthVolume: Not yet implemented\n");
1009 /* return the volume flags (VT* constants in volser.h) associated with this
1013 SAFSVolGetFlags(acid, atid, aflags)
1014 struct rx_call *acid;
1020 code = VolGetFlags(acid, atid, aflags);
1021 osi_auditU(acid, VS_GetFlgsEvent, code, AUD_LONG, atid, AUD_END);
1026 VolGetFlags(acid, atid, aflags)
1027 struct rx_call *acid;
1031 register struct volser_trans *tt;
1033 tt = FindTrans(atid);
1036 if (tt->vflags & VTDeleted) {
1037 Log("1 Volser: VolGetFlags: volume %u has been deleted \n",
1042 strcpy(tt->lastProcName, "GetFlags");
1043 tt->rxCallPtr = acid;
1044 *aflags = tt->vflags;
1045 tt->rxCallPtr = (struct rx_call *)0;
1047 return VOLSERTRELE_ERROR;
1052 /* Change the volume flags (VT* constants in volser.h) associated with this
1053 * transaction. Effects take place immediately on volume, although volume
1054 * remains attached as usual by the transaction.
1057 SAFSVolSetFlags(acid, atid, aflags)
1058 struct rx_call *acid;
1064 code = VolSetFlags(acid, atid, aflags);
1065 osi_auditU(acid, VS_SetFlgsEvent, code, AUD_LONG, atid, AUD_LONG, aflags,
1071 VolSetFlags(acid, atid, aflags)
1072 struct rx_call *acid;
1076 register struct volser_trans *tt;
1077 register struct Volume *vp;
1079 char caller[MAXKTCNAMELEN];
1081 if (!afsconf_SuperUser(tdir, acid, caller))
1082 return VOLSERBAD_ACCESS; /*not a super user */
1083 /* find the trans */
1084 tt = FindTrans(atid);
1087 if (tt->vflags & VTDeleted) {
1088 Log("1 Volser: VolSetFlags: volume %u has been deleted \n",
1093 strcpy(tt->lastProcName, "SetFlags");
1094 tt->rxCallPtr = acid;
1095 vp = tt->volume; /* pull volume out of transaction */
1097 /* check if we're allowed to make any updates */
1098 if (tt->iflags & ITReadOnly) {
1103 /* handle delete-on-salvage flag */
1104 if (aflags & VTDeleteOnSalvage) {
1105 V_destroyMe(tt->volume) = DESTROY_ME;
1107 V_destroyMe(tt->volume) = 0;
1110 if (aflags & VTOutOfService) {
1111 V_inService(vp) = 0;
1113 V_inService(vp) = 1;
1115 VUpdateVolume(&error, vp);
1116 tt->vflags = aflags;
1117 tt->rxCallPtr = (struct rx_call *)0;
1118 if (TRELE(tt) && !error)
1119 return VOLSERTRELE_ERROR;
1124 /* dumpS the volume associated with a particular transaction from a particular
1125 * date. Send the dump to a different transaction (destTrans) on the server
1126 * specified by the destServer structure.
1129 SAFSVolForward(acid, fromTrans, fromDate, destination, destTrans, cookie)
1130 struct rx_call *acid;
1131 afs_int32 fromTrans;
1133 struct destServer *destination;
1134 struct restoreCookie *cookie;
1135 afs_int32 destTrans;
1140 VolForward(acid, fromTrans, fromDate, destination, destTrans, cookie);
1141 osi_auditU(acid, VS_ForwardEvent, code, AUD_LONG, fromTrans, AUD_HOST,
1142 destination->destHost, AUD_LONG, destTrans, AUD_END);
1147 VolForward(acid, fromTrans, fromDate, destination, destTrans, cookie)
1148 struct rx_call *acid;
1149 afs_int32 fromTrans;
1151 struct destServer *destination;
1152 struct restoreCookie *cookie;
1153 afs_int32 destTrans;
1155 register struct volser_trans *tt;
1156 register afs_int32 code;
1157 register struct rx_connection *tcon;
1158 struct rx_call *tcall;
1159 register struct Volume *vp;
1160 struct rx_securityClass *securityObject;
1161 afs_int32 securityIndex;
1162 char caller[MAXKTCNAMELEN];
1164 if (!afsconf_SuperUser(tdir, acid, caller))
1165 return VOLSERBAD_ACCESS; /*not a super user */
1166 /* initialize things */
1167 tcon = (struct rx_connection *)0;
1168 tt = (struct volser_trans *)0;
1170 /* find the local transaction */
1171 tt = FindTrans(fromTrans);
1174 if (tt->vflags & VTDeleted) {
1175 Log("1 Volser: VolForward: volume %u has been deleted \n", tt->volid);
1180 strcpy(tt->lastProcName, "Forward");
1182 /* get auth info for the this connection (uses afs from ticket file) */
1183 code = afsconf_ClientAuth(tdir, &securityObject, &securityIndex);
1189 /* make an rpc connection to the other server */
1191 rx_NewConnection(htonl(destination->destHost),
1192 htons(destination->destPort), VOLSERVICE_ID,
1193 securityObject, securityIndex);
1195 tt->rxCallPtr = (struct rx_call *)0;
1199 tcall = rx_NewCall(tcon);
1200 tt->rxCallPtr = tcall;
1201 /* start restore going. fromdate == 0 --> doing an incremental dump/restore */
1202 code = StartAFSVolRestore(tcall, destTrans, (fromDate ? 1 : 0), cookie);
1207 /* these next calls implictly call rx_Write when writing out data */
1208 code = DumpVolume(tcall, vp, fromDate, 0); /* last field = don't dump all dirs */
1211 EndAFSVolRestore(tcall); /* probably doesn't do much */
1212 tt->rxCallPtr = (struct rx_call *)0;
1213 code = rx_EndCall(tcall, 0);
1214 rx_DestroyConnection(tcon); /* done with the connection */
1219 return VOLSERTRELE_ERROR;
1225 (void)rx_EndCall(tcall, 0);
1226 rx_DestroyConnection(tcon);
1229 tt->rxCallPtr = (struct rx_call *)0;
1235 /* Start a dump and send it to multiple places simultaneously.
1236 * If this returns an error (eg, return ENOENT), it means that
1237 * none of the releases worked. If this returns 0, that means
1238 * that one or more of the releases worked, and the caller has
1239 * to examine the results array to see which one(s).
1240 * This will only do EITHER incremental or full, not both, so it's
1241 * the caller's responsibility to be sure that all the destinations
1242 * need just an incremental (and from the same time), if that's
1246 SAFSVolForwardMultiple(acid, fromTrans, fromDate, destinations, spare, cookie,
1248 struct rx_call *acid;
1249 afs_int32 fromTrans;
1252 manyDests *destinations;
1253 struct restoreCookie *cookie;
1254 manyResults *results;
1256 afs_int32 securityIndex;
1257 struct rx_securityClass *securityObject;
1258 char caller[MAXKTCNAMELEN];
1259 struct volser_trans *tt;
1260 afs_int32 ec, code, *codes;
1261 struct rx_connection **tcons;
1262 struct rx_call **tcalls;
1264 int i, nconns, is_incremental;
1267 memset(results, 0, sizeof(manyResults));
1269 if (!afsconf_SuperUser(tdir, acid, caller))
1270 return VOLSERBAD_ACCESS; /*not a super user */
1271 tt = FindTrans(fromTrans);
1274 if (tt->vflags & VTDeleted) {
1275 Log("1 Volser: VolForward: volume %u has been deleted \n", tt->volid);
1280 strcpy(tt->lastProcName, "ForwardMulti");
1282 /* (fromDate == 0) ==> incremental dump */
1283 is_incremental = (fromDate ? 1 : 0);
1285 i = results->manyResults_len = destinations->manyDests_len;
1286 results->manyResults_val = codes =
1287 (afs_int32 *) malloc(i * sizeof(afs_int32));
1289 (struct rx_connection **)malloc(i * sizeof(struct rx_connection *));
1290 tcalls = (struct rx_call **)malloc(i * sizeof(struct rx_call *));
1292 /* get auth info for this connection (uses afs from ticket file) */
1293 code = afsconf_ClientAuth(tdir, &securityObject, &securityIndex);
1295 goto fail; /* in order to audit each failure */
1298 /* make connections to all the other servers */
1299 for (i = 0; i < destinations->manyDests_len; i++) {
1300 struct replica *dest = &(destinations->manyDests_val[i]);
1302 rx_NewConnection(htonl(dest->server.destHost),
1303 htons(dest->server.destPort), VOLSERVICE_ID,
1304 securityObject, securityIndex);
1306 codes[i] = ENOTCONN;
1308 if (!(tcalls[i] = rx_NewCall(tcons[i])))
1309 codes[i] = ENOTCONN;
1312 StartAFSVolRestore(tcalls[i], dest->trans, is_incremental,
1315 (void)rx_EndCall(tcalls[i], 0);
1317 rx_DestroyConnection(tcons[i]);
1324 /* these next calls implictly call rx_Write when writing out data */
1325 code = DumpVolMulti(tcalls, i, vp, fromDate, 0, codes);
1329 for (i--; i >= 0; i--) {
1330 struct replica *dest = &(destinations->manyDests_val[i]);
1332 if (!code && tcalls[i] && !codes[i]) {
1333 EndAFSVolRestore(tcalls[i]);
1336 ec = rx_EndCall(tcalls[i], 0);
1341 rx_DestroyConnection(tcons[i]); /* done with the connection */
1344 osi_auditU(acid, VS_ForwardEvent, (code ? code : codes[i]), AUD_LONG,
1345 fromTrans, AUD_HOST, dest->server.destHost, AUD_LONG,
1346 dest->trans, AUD_END);
1352 tt->rxCallPtr = (struct rx_call *)0;
1353 if (TRELE(tt) && !code) /* return the first code if it's set */
1354 return VOLSERTRELE_ERROR;
1361 SAFSVolDump(acid, fromTrans, fromDate)
1362 struct rx_call *acid;
1363 afs_int32 fromTrans;
1368 code = VolDump(acid, fromTrans, fromDate);
1369 osi_auditU(acid, VS_DumpEvent, code, AUD_LONG, fromTrans, AUD_END);
1374 VolDump(acid, fromTrans, fromDate)
1375 struct rx_call *acid;
1376 afs_int32 fromTrans;
1380 register struct volser_trans *tt;
1381 char caller[MAXKTCNAMELEN];
1383 if (!afsconf_SuperUser(tdir, acid, caller))
1384 return VOLSERBAD_ACCESS; /*not a super user */
1385 tt = FindTrans(fromTrans);
1388 if (tt->vflags & VTDeleted) {
1389 Log("1 Volser: VolDump: volume %u has been deleted \n", tt->volid);
1393 strcpy(tt->lastProcName, "Dump");
1394 tt->rxCallPtr = acid;
1395 code = DumpVolume(acid, tt->volume, fromDate, 1); /* squirt out the volume's data, too */
1397 tt->rxCallPtr = (struct rx_call *)0;
1401 tt->rxCallPtr = (struct rx_call *)0;
1404 return VOLSERTRELE_ERROR;
1410 * Ha! No more helper process!
1413 SAFSVolRestore(acid, atrans, aflags, cookie)
1414 struct rx_call *acid;
1417 struct restoreCookie *cookie;
1421 code = VolRestore(acid, atrans, aflags, cookie);
1422 osi_auditU(acid, VS_RestoreEvent, code, AUD_LONG, atrans, AUD_END);
1427 VolRestore(acid, atrans, aflags, cookie)
1428 struct rx_call *acid;
1431 struct restoreCookie *cookie;
1433 register struct volser_trans *tt;
1434 register afs_int32 code, tcode;
1435 char caller[MAXKTCNAMELEN];
1437 if (!afsconf_SuperUser(tdir, acid, caller))
1438 return VOLSERBAD_ACCESS; /*not a super user */
1439 tt = FindTrans(atrans);
1442 if (tt->vflags & VTDeleted) {
1443 Log("1 Volser: VolRestore: volume %u has been deleted \n", tt->volid);
1447 strcpy(tt->lastProcName, "Restore");
1448 tt->rxCallPtr = acid;
1449 code = RestoreVolume(acid, tt->volume, (aflags & 1), cookie); /* last is incrementalp */
1450 FSYNC_askfs(tt->volid, NULL, FSYNC_RESTOREVOLUME, 0l); /*break call backs on the
1451 * restored volume */
1452 tt->rxCallPtr = (struct rx_call *)0;
1455 return (code ? code : tcode);
1458 /* end a transaction, returning the transaction's final error code in rcode */
1460 SAFSVolEndTrans(acid, destTrans, rcode)
1461 struct rx_call *acid;
1462 afs_int32 destTrans;
1467 code = VolEndTrans(acid, destTrans, rcode);
1468 osi_auditU(acid, VS_EndTrnEvent, code, AUD_LONG, destTrans, AUD_END);
1473 VolEndTrans(acid, destTrans, rcode)
1474 struct rx_call *acid;
1475 afs_int32 destTrans;
1478 register struct volser_trans *tt;
1479 char caller[MAXKTCNAMELEN];
1481 if (!afsconf_SuperUser(tdir, acid, caller))
1482 return VOLSERBAD_ACCESS; /*not a super user */
1483 tt = FindTrans(destTrans);
1487 *rcode = tt->returnCode;
1488 DeleteTrans(tt); /* this does an implicit TRELE */
1494 SAFSVolSetForwarding(acid, atid, anewsite)
1495 struct rx_call *acid;
1501 code = VolSetForwarding(acid, atid, anewsite);
1502 osi_auditU(acid, VS_SetForwEvent, code, AUD_LONG, atid, AUD_HOST,
1508 VolSetForwarding(acid, atid, anewsite)
1509 struct rx_call *acid;
1514 register struct volser_trans *tt;
1515 char caller[MAXKTCNAMELEN];
1517 if (!afsconf_SuperUser(tdir, acid, caller))
1518 return VOLSERBAD_ACCESS; /*not a super user */
1519 tt = FindTrans(atid);
1522 if (tt->vflags & VTDeleted) {
1523 Log("1 Volser: VolSetForwarding: volume %u has been deleted \n",
1528 strcpy(tt->lastProcName, "SetForwarding");
1529 tt->rxCallPtr = acid;
1530 FSYNC_askfs(tt->volid, NULL, FSYNC_MOVEVOLUME, anewsite);
1531 tt->rxCallPtr = (struct rx_call *)0;
1533 return VOLSERTRELE_ERROR;
1539 SAFSVolGetStatus(acid, atrans, astatus)
1540 struct rx_call *acid;
1542 register struct volser_status *astatus;
1546 code = VolGetStatus(acid, atrans, astatus);
1547 osi_auditU(acid, VS_GetStatEvent, code, AUD_LONG, atrans, AUD_END);
1552 VolGetStatus(acid, atrans, astatus)
1553 struct rx_call *acid;
1555 register struct volser_status *astatus;
1557 register struct Volume *tv;
1558 register struct VolumeDiskData *td;
1559 struct volser_trans *tt;
1562 tt = FindTrans(atrans);
1565 if (tt->vflags & VTDeleted) {
1566 Log("1 Volser: VolGetStatus: volume %u has been deleted \n",
1571 strcpy(tt->lastProcName, "GetStatus");
1572 tt->rxCallPtr = acid;
1575 tt->rxCallPtr = (struct rx_call *)0;
1580 td = &tv->header->diskstuff;
1581 astatus->volID = td->id;
1582 astatus->nextUnique = td->uniquifier;
1583 astatus->type = td->type;
1584 astatus->parentID = td->parentId;
1585 astatus->cloneID = td->cloneId;
1586 astatus->backupID = td->backupId;
1587 astatus->restoredFromID = td->restoredFromId;
1588 astatus->maxQuota = td->maxquota;
1589 astatus->minQuota = td->minquota;
1590 astatus->owner = td->owner;
1591 astatus->creationDate = td->creationDate;
1592 astatus->accessDate = td->accessDate;
1593 astatus->updateDate = td->updateDate;
1594 astatus->expirationDate = td->expirationDate;
1595 astatus->backupDate = td->backupDate;
1596 astatus->copyDate = td->copyDate;
1597 tt->rxCallPtr = (struct rx_call *)0;
1599 return VOLSERTRELE_ERROR;
1605 SAFSVolSetInfo(acid, atrans, astatus)
1606 struct rx_call *acid;
1608 register struct volintInfo *astatus;
1612 code = VolSetInfo(acid, atrans, astatus);
1613 osi_auditU(acid, VS_SetInfoEvent, code, AUD_LONG, atrans, AUD_END);
1618 VolSetInfo(acid, atrans, astatus)
1619 struct rx_call *acid;
1621 register struct volintInfo *astatus;
1623 register struct Volume *tv;
1624 register struct VolumeDiskData *td;
1625 struct volser_trans *tt;
1626 char caller[MAXKTCNAMELEN];
1629 if (!afsconf_SuperUser(tdir, acid, caller))
1630 return VOLSERBAD_ACCESS; /*not a super user */
1631 tt = FindTrans(atrans);
1634 if (tt->vflags & VTDeleted) {
1635 Log("1 Volser: VolSetInfo: volume %u has been deleted \n", tt->volid);
1639 strcpy(tt->lastProcName, "SetStatus");
1640 tt->rxCallPtr = acid;
1643 tt->rxCallPtr = (struct rx_call *)0;
1648 td = &tv->header->diskstuff;
1650 * Add more fields as necessary
1652 if (astatus->maxquota != -1)
1653 td->maxquota = astatus->maxquota;
1654 if (astatus->dayUse != -1)
1655 td->dayUse = astatus->dayUse;
1656 VUpdateVolume(&error, tv);
1657 tt->rxCallPtr = (struct rx_call *)0;
1659 return VOLSERTRELE_ERROR;
1665 SAFSVolGetName(acid, atrans, aname)
1666 struct rx_call *acid;
1672 code = VolGetName(acid, atrans, aname);
1673 osi_auditU(acid, VS_GetNameEvent, code, AUD_LONG, atrans, AUD_END);
1678 VolGetName(acid, atrans, aname)
1679 struct rx_call *acid;
1683 register struct Volume *tv;
1684 register struct VolumeDiskData *td;
1685 struct volser_trans *tt;
1689 tt = FindTrans(atrans);
1692 if (tt->vflags & VTDeleted) {
1693 Log("1 Volser: VolGetName: volume %u has been deleted \n", tt->volid);
1697 strcpy(tt->lastProcName, "GetName");
1698 tt->rxCallPtr = acid;
1701 tt->rxCallPtr = (struct rx_call *)0;
1706 td = &tv->header->diskstuff;
1707 len = strlen(td->name) + 1; /* don't forget the null */
1709 tt->rxCallPtr = (struct rx_call *)0;
1713 *aname = (char *)malloc(len);
1714 strcpy(*aname, td->name);
1715 tt->rxCallPtr = (struct rx_call *)0;
1717 return VOLSERTRELE_ERROR;
1722 /*this is a handshake to indicate that the next call will be SAFSVolRestore
1725 SAFSVolSignalRestore(acid, volname, volType, parentId, cloneId)
1726 struct rx_call *acid;
1728 afs_int32 parentId, cloneId;
1735 /*return a list of all partitions on the server. The non mounted
1736 *partitions are returned as -1 in the corresponding slot in partIds*/
1738 SAFSVolListPartitions(acid, partIds)
1739 struct rx_call *acid;
1740 struct pIDs *partIds;
1744 code = VolListPartitions(acid, partIds);
1745 osi_auditU(acid, VS_ListParEvent, code, AUD_END);
1750 VolListPartitions(acid, partIds)
1751 struct rx_call *acid;
1752 struct pIDs *partIds;
1758 strcpy(namehead, "/vicep"); /*7 including null terminator */
1760 /* Just return attached partitions. */
1762 for (i = 0; i < 26; i++) {
1763 namehead[6] = i + 'a';
1764 if (VGetPartition(namehead, 0))
1765 partIds->partIds[i] = VGetPartition(namehead, 0) ? i : -1;
1771 /*return a list of all partitions on the server. The non mounted
1772 *partitions are returned as -1 in the corresponding slot in partIds*/
1774 SAFSVolXListPartitions(acid, pEntries)
1775 struct rx_call *acid;
1776 struct partEntries *pEntries;
1780 code = XVolListPartitions(acid, pEntries);
1781 osi_auditU(acid, VS_ListParEvent, code, AUD_END);
1786 XVolListPartitions(acid, pEntries)
1787 struct rx_call *acid;
1788 struct partEntries *pEntries;
1790 struct stat rbuf, pbuf;
1792 struct partList partList;
1793 struct DiskPartition *dp;
1796 strcpy(namehead, "/vicep"); /*7 including null terminator */
1798 /* Only report attached partitions */
1799 for (i = 0; i < VOLMAXPARTS; i++) {
1801 namehead[6] = i + 'a';
1805 namehead[6] = 'a' + (k / 26);
1806 namehead[7] = 'a' + (k % 26);
1809 dp = VGetPartition(namehead, 0);
1811 partList.partId[j++] = i;
1813 pEntries->partEntries_val = (afs_int32 *) malloc(j * sizeof(int));
1814 memcpy((char *)pEntries->partEntries_val, (char *)&partList,
1816 pEntries->partEntries_len = j;
1821 /*extract the volume id from string vname. Its of the form " V0*<id>.vol "*/
1827 char name[VOLSER_MAXVOLNAME + 1];
1829 strcpy(name, vname);
1831 while (name[i] == 'V' || name[i] == '0')
1834 name[11] = '\0'; /* smash the "." */
1835 return (atol(&name[i]));
1838 /*return the name of the next volume header in the directory associated with dirp and dp.
1839 *the volume id is returned in volid, and volume header name is returned in volname*/
1840 GetNextVol(DIR * dirp, char *volname, afs_int32 * volid)
1844 dp = readdir(dirp); /*read next entry in the directory */
1847 if ((dp->d_name[0] == 'V') && !strcmp(&(dp->d_name[11]), VHDREXT)) {
1848 *volid = ExtractVolId(dp->d_name);
1849 strcpy(volname, dp->d_name);
1850 return 0; /*return the name of the file representing a volume */
1852 strcpy(volname, "");
1853 return 0; /*volname doesnot represent a volume */
1856 strcpy(volname, "EOD");
1857 return 0; /*end of directory */
1862 /*return the header information about the <volid> */
1864 SAFSVolListOneVolume(acid, partid, volumeId, volumeInfo)
1865 struct rx_call *acid;
1866 afs_int32 volumeId, partid;
1867 volEntries *volumeInfo;
1871 code = VolListOneVolume(acid, partid, volumeId, volumeInfo);
1872 osi_auditU(acid, VS_Lst1VolEvent, code, AUD_LONG, volumeId, AUD_END);
1877 VolListOneVolume(acid, partid, volumeId, volumeInfo)
1878 struct rx_call *acid;
1879 afs_int32 volumeId, partid;
1880 volEntries *volumeInfo;
1883 register struct Volume *tv;
1884 struct DiskPartition *partP;
1885 struct volser_trans *ttc;
1886 char pname[9], volname[20];
1887 afs_int32 error = 0;
1893 volumeInfo->volEntries_val = (volintInfo *) malloc(sizeof(volintInfo));
1894 pntr = volumeInfo->volEntries_val;
1895 volumeInfo->volEntries_len = 1;
1896 if (GetPartName(partid, pname))
1897 return VOLSERILLEGAL_PARTITION;
1898 if (!(partP = VGetPartition(pname, 0)))
1899 return VOLSERILLEGAL_PARTITION;
1900 dirp = opendir(VPartitionPath(partP));
1902 return VOLSERILLEGAL_PARTITION;
1903 strcpy(volname, "");
1904 ttc = (struct volser_trans *)0;
1905 tv = (Volume *) 0; /* volume not attached */
1907 while (strcmp(volname, "EOD") && !found) { /*while there are more volumes in the partition */
1909 if (!strcmp(volname, "")) { /* its not a volume, fetch next file */
1910 GetNextVol(dirp, volname, &volid);
1911 continue; /*back to while loop */
1914 if (volid == volumeId) { /*copy other things too */
1916 IOMGR_Poll(); /*make sure that the client doesnot time out */
1917 ttc = NewTrans(volid, partid);
1919 pntr->status = VBUSY;
1920 pntr->volid = volid;
1923 tv = VAttachVolumeByName(&error, pname, volname, V_READONLY);
1925 pntr->status = 0; /*things are messed up */
1926 strcpy(pntr->name, volname);
1927 pntr->volid = volid;
1928 Log("1 Volser: ListVolumes: Could not attach volume %u (%s:%s), error=%d\n", volid, pname, volname, error);
1931 if (tv->header->diskstuff.destroyMe == DESTROY_ME) {
1932 /*this volume will be salvaged */
1934 strcpy(pntr->name, volname);
1935 pntr->volid = volid;
1936 Log("1 Volser: ListVolumes: Volume %u (%s) will be destroyed on next salvage\n", volid, volname);
1940 if (tv->header->diskstuff.needsSalvaged) {
1941 /*this volume will be salvaged */
1943 strcpy(pntr->name, volname);
1944 pntr->volid = volid;
1945 Log("1 Volser: ListVolumes: Volume %u (%s) needs to be salvaged\n", volid, volname);
1949 /*read in the relevant info */
1950 pntr->status = VOK; /*its ok */
1951 pntr->volid = tv->header->diskstuff.id;
1952 strcpy(pntr->name, tv->header->diskstuff.name);
1953 pntr->type = tv->header->diskstuff.type; /*if ro volume */
1954 pntr->cloneID = tv->header->diskstuff.cloneId; /*if rw volume */
1955 pntr->backupID = tv->header->diskstuff.backupId;
1956 pntr->parentID = tv->header->diskstuff.parentId;
1957 pntr->copyDate = tv->header->diskstuff.copyDate;
1958 pntr->inUse = tv->header->diskstuff.inUse;
1959 pntr->size = tv->header->diskstuff.diskused;
1960 pntr->needsSalvaged = tv->header->diskstuff.needsSalvaged;
1961 pntr->destroyMe = tv->header->diskstuff.destroyMe;
1962 pntr->maxquota = tv->header->diskstuff.maxquota;
1963 pntr->filecount = tv->header->diskstuff.filecount;
1964 now = FT_ApproxTime();
1965 if (now - tv->header->diskstuff.dayUseDate > OneDay)
1968 pntr->dayUse = tv->header->diskstuff.dayUse;
1969 pntr->creationDate = tv->header->diskstuff.creationDate;
1970 pntr->accessDate = tv->header->diskstuff.accessDate;
1971 pntr->updateDate = tv->header->diskstuff.updateDate;
1972 pntr->backupDate = tv->header->diskstuff.backupDate;
1973 pntr->spare0 = tv->header->diskstuff.minquota;
1975 (long)tv->header->diskstuff.weekUse[0] +
1976 (long)tv->header->diskstuff.weekUse[1] +
1977 (long)tv->header->diskstuff.weekUse[2] +
1978 (long)tv->header->diskstuff.weekUse[3] +
1979 (long)tv->header->diskstuff.weekUse[4] +
1980 (long)tv->header->diskstuff.weekUse[5] +
1981 (long)tv->header->diskstuff.weekUse[6];
1982 pntr->flags = pntr->spare2 = pntr->spare3 = (long)0;
1983 VDetachVolume(&error, tv); /*free the volume */
1986 pntr->status = 0; /*things are messed up */
1987 strcpy(pntr->name, volname);
1988 Log("1 Volser: ListVolumes: Could not detach volume %s\n",
1993 GetNextVol(dirp, volname, &volid);
1997 VDetachVolume(&error, tv);
2002 ttc = (struct volser_trans *)0;
2012 /*------------------------------------------------------------------------
2013 * EXPORTED SAFSVolXListOneVolume
2016 * Returns extended info on volume a_volID on partition a_partID.
2019 * a_rxCidP : Pointer to the Rx call we're performing.
2020 * a_partID : Partition for which we want the extended list.
2021 * a_volID : Volume ID we wish to know about.
2022 * a_volumeXInfoP : Ptr to the extended info blob.
2025 * 0 Successful operation
2026 * VOLSERILLEGAL_PARTITION if we got a bogus partition ID
2029 * Nothing interesting.
2033 *------------------------------------------------------------------------*/
2036 SAFSVolXListOneVolume(a_rxCidP, a_partID, a_volID, a_volumeXInfoP)
2037 struct rx_call *a_rxCidP;
2040 volXEntries *a_volumeXInfoP;
2044 code = VolXListOneVolume(a_rxCidP, a_partID, a_volID, a_volumeXInfoP);
2045 osi_auditU(a_rxCidP, VS_XLst1VlEvent, code, AUD_LONG, a_volID, AUD_END);
2050 VolXListOneVolume(a_rxCidP, a_partID, a_volID, a_volumeXInfoP)
2051 struct rx_call *a_rxCidP;
2054 volXEntries *a_volumeXInfoP;
2056 { /*SAFSVolXListOneVolume */
2058 volintXInfo *xInfoP; /*Ptr to the extended vol info */
2059 register struct Volume *tv; /*Volume ptr */
2060 struct volser_trans *ttc; /*Volume transaction ptr */
2061 struct DiskPartition *partP; /*Ptr to partition */
2062 char pname[9], volname[20]; /*Partition, volume names */
2063 afs_int32 error; /*Error code */
2064 afs_int32 code; /*Return code */
2065 DIR *dirp; /*Partition directory ptr */
2066 afs_int32 currVolID; /*Current volume ID */
2067 int found = 0; /*Did we find the volume we need? */
2068 struct VolumeDiskData *volDiskDataP; /*Ptr to on-disk volume data */
2069 int numStatBytes; /*Num stat bytes to copy per volume */
2073 * Set up our pointers for action, marking our structure to hold exactly
2074 * one entry. Also, assume we'll fail in our quest.
2076 a_volumeXInfoP->volXEntries_val =
2077 (volintXInfo *) malloc(sizeof(volintXInfo));
2078 xInfoP = a_volumeXInfoP->volXEntries_val;
2079 a_volumeXInfoP->volXEntries_len = 1;
2083 * If the partition name we've been given is bad, bogue out.
2085 if (GetPartName(a_partID, pname))
2086 return (VOLSERILLEGAL_PARTITION);
2089 * Open the directory representing the given AFS parttion. If we can't
2092 if (!(partP = VGetPartition(pname, 0)))
2093 return VOLSERILLEGAL_PARTITION;
2094 dirp = opendir(VPartitionPath(partP));
2096 return (VOLSERILLEGAL_PARTITION);
2099 * Sweep through the partition directory, looking for the desired entry.
2100 * First, of course, figure out how many stat bytes to copy out of each
2104 4 * ((2 * VOLINT_STATS_NUM_RWINFO_FIELDS) +
2105 (4 * VOLINT_STATS_NUM_TIME_FIELDS));
2106 strcpy(volname, "");
2107 ttc = (struct volser_trans *)0; /*No transaction yet */
2108 tv = (Volume *) 0; /*Volume not yet attached */
2110 while (strcmp(volname, "EOD") && !found) {
2112 * If this is not a volume, move on to the next entry in the
2113 * partition's directory.
2115 if (!strcmp(volname, "")) {
2116 GetNextVol(dirp, volname, &currVolID);
2120 if (currVolID == a_volID) {
2122 * We found the volume entry we're interested. Pull out the
2123 * extended information, remembering to poll (so that the client
2124 * doesn't time out) and to set up a transaction on the volume.
2128 ttc = NewTrans(currVolID, a_partID);
2131 * Couldn't get a transaction on this volume; let our caller
2134 xInfoP->status = VBUSY;
2135 xInfoP->volid = currVolID;
2140 * Attach the volume, give up on the volume if we can't.
2142 tv = VAttachVolumeByName(&error, pname, volname, V_READONLY);
2144 xInfoP->status = 0; /*things are messed up */
2145 strcpy(xInfoP->name, volname);
2146 xInfoP->volid = currVolID;
2147 Log("1 Volser: XListOneVolume: Could not attach volume %u\n",
2153 * Also bag out on this volume if it's been marked as needing a
2154 * salvage or to-be-destroyed.
2156 volDiskDataP = &(tv->header->diskstuff);
2157 if (volDiskDataP->destroyMe == DESTROY_ME) {
2159 strcpy(xInfoP->name, volname);
2160 xInfoP->volid = currVolID;
2161 Log("1 Volser: XListOneVolume: Volume %u will be destroyed on next salvage\n", currVolID);
2165 if (volDiskDataP->needsSalvaged) {
2167 strcpy(xInfoP->name, volname);
2168 xInfoP->volid = currVolID;
2169 Log("1 Volser: XListOneVolume: Volume %u needs to be salvaged\n", currVolID);
2174 * Pull out the desired info and stuff it into the area we'll be
2175 * returning to our caller.
2177 strcpy(xInfoP->name, volDiskDataP->name);
2178 xInfoP->volid = volDiskDataP->id;
2179 xInfoP->type = volDiskDataP->type;
2180 xInfoP->backupID = volDiskDataP->backupId;
2181 xInfoP->parentID = volDiskDataP->parentId;
2182 xInfoP->cloneID = volDiskDataP->cloneId;
2183 xInfoP->status = VOK;
2184 xInfoP->copyDate = volDiskDataP->copyDate;
2185 xInfoP->inUse = volDiskDataP->inUse;
2186 xInfoP->creationDate = volDiskDataP->creationDate;
2187 xInfoP->accessDate = volDiskDataP->accessDate;
2188 xInfoP->updateDate = volDiskDataP->updateDate;
2189 xInfoP->backupDate = volDiskDataP->backupDate;
2190 now = FT_ApproxTime();
2191 if (now - volDiskDataP->dayUseDate > OneDay)
2194 xInfoP->dayUse = volDiskDataP->dayUse;
2195 xInfoP->filecount = volDiskDataP->filecount;
2196 xInfoP->maxquota = volDiskDataP->maxquota;
2197 xInfoP->size = volDiskDataP->diskused;
2200 * Copy out the stat fields in a single operation.
2202 memcpy((char *)&(xInfoP->stat_reads[0]),
2203 (char *)&(volDiskDataP->stat_reads[0]), numStatBytes);
2206 * We're done copying. Detach the volume and iterate (at this
2207 * point, since we found our volume, we'll then drop out of the
2210 VDetachVolume(&error, tv);
2214 strcpy(xInfoP->name, volname);
2215 Log("1 Volser: XListOneVolumes Couldn't detach volume %s\n",
2221 * At this point, we're golden.
2224 } /*Found desired volume */
2225 GetNextVol(dirp, volname, &currVolID);
2229 * Drop the transaction we have for this volume.
2233 VDetachVolume(&error, tv);
2238 ttc = (struct volser_trans *)0;
2242 * Clean up before going to dinner: close the partition directory,
2243 * return the proper value.
2248 } /*SAFSVolXListOneVolume */
2250 /*returns all the volumes on partition partid. If flags = 1 then all the
2251 * relevant info about the volumes is also returned */
2253 SAFSVolListVolumes(acid, partid, flags, volumeInfo)
2254 struct rx_call *acid;
2255 afs_int32 flags, partid;
2256 volEntries *volumeInfo;
2260 code = VolListVolumes(acid, partid, flags, volumeInfo);
2261 osi_auditU(acid, VS_ListVolEvent, code, AUD_END);
2266 VolListVolumes(acid, partid, flags, volumeInfo)
2267 struct rx_call *acid;
2268 afs_int32 flags, partid;
2269 volEntries *volumeInfo;
2272 register struct Volume *tv;
2273 struct DiskPartition *partP;
2274 struct volser_trans *ttc;
2275 afs_int32 allocSize = 1000; /*to be changed to a larger figure */
2276 char pname[9], volname[20];
2277 afs_int32 error = 0;
2282 volumeInfo->volEntries_val =
2283 (volintInfo *) malloc(allocSize * sizeof(volintInfo));
2284 pntr = volumeInfo->volEntries_val;
2285 volumeInfo->volEntries_len = 0;
2286 if (GetPartName(partid, pname))
2287 return VOLSERILLEGAL_PARTITION;
2288 if (!(partP = VGetPartition(pname, 0)))
2289 return VOLSERILLEGAL_PARTITION;
2290 dirp = opendir(VPartitionPath(partP));
2292 return VOLSERILLEGAL_PARTITION;
2293 strcpy(volname, "");
2294 while (strcmp(volname, "EOD")) { /*while there are more partitions in the partition */
2295 ttc = (struct volser_trans *)0; /* new one for each pass */
2296 tv = (Volume *) 0; /* volume not attached */
2298 if (!strcmp(volname, "")) { /* its not a volume, fetch next file */
2299 GetNextVol(dirp, volname, &volid);
2300 continue; /*back to while loop */
2303 if (flags) { /*copy other things too */
2304 IOMGR_Poll(); /*make sure that the client doesnot time out */
2305 ttc = NewTrans(volid, partid);
2307 pntr->status = VBUSY;
2308 pntr->volid = volid;
2311 tv = VAttachVolumeByName(&error, pname, volname, V_READONLY);
2313 pntr->status = 0; /*things are messed up */
2314 strcpy(pntr->name, volname);
2315 pntr->volid = volid;
2316 Log("1 Volser: ListVolumes: Could not attach volume %u (%s) error=%d\n", volid, volname, error);
2319 if (tv->header->diskstuff.needsSalvaged) {
2320 /*this volume will be salvaged */
2322 strcpy(pntr->name, volname);
2323 pntr->volid = volid;
2324 Log("1 Volser: ListVolumes: Volume %u (%s) needs to be salvaged\n", volid, volname);
2328 if (tv->header->diskstuff.destroyMe == DESTROY_ME) {
2329 /*this volume will be salvaged */
2332 /*read in the relevant info */
2333 pntr->status = VOK; /*its ok */
2334 pntr->volid = tv->header->diskstuff.id;
2335 strcpy(pntr->name, tv->header->diskstuff.name);
2336 pntr->type = tv->header->diskstuff.type; /*if ro volume */
2337 pntr->cloneID = tv->header->diskstuff.cloneId; /*if rw volume */
2338 pntr->backupID = tv->header->diskstuff.backupId;
2339 pntr->parentID = tv->header->diskstuff.parentId;
2340 pntr->copyDate = tv->header->diskstuff.copyDate;
2341 pntr->inUse = tv->header->diskstuff.inUse;
2342 pntr->size = tv->header->diskstuff.diskused;
2343 pntr->needsSalvaged = tv->header->diskstuff.needsSalvaged;
2344 pntr->maxquota = tv->header->diskstuff.maxquota;
2345 pntr->filecount = tv->header->diskstuff.filecount;
2346 now = FT_ApproxTime();
2347 if (now - tv->header->diskstuff.dayUseDate > OneDay)
2350 pntr->dayUse = tv->header->diskstuff.dayUse;
2351 pntr->creationDate = tv->header->diskstuff.creationDate;
2352 pntr->accessDate = tv->header->diskstuff.accessDate;
2353 pntr->updateDate = tv->header->diskstuff.updateDate;
2354 pntr->backupDate = tv->header->diskstuff.backupDate;
2355 pntr->spare0 = tv->header->diskstuff.minquota;
2357 (long)tv->header->diskstuff.weekUse[0] +
2358 (long)tv->header->diskstuff.weekUse[1] +
2359 (long)tv->header->diskstuff.weekUse[2] +
2360 (long)tv->header->diskstuff.weekUse[3] +
2361 (long)tv->header->diskstuff.weekUse[4] +
2362 (long)tv->header->diskstuff.weekUse[5] +
2363 (long)tv->header->diskstuff.weekUse[6];
2364 pntr->flags = pntr->spare2 = pntr->spare3 = (long)0;
2365 VDetachVolume(&error, tv); /*free the volume */
2368 pntr->status = 0; /*things are messed up */
2369 strcpy(pntr->name, volname);
2370 Log("1 Volser: ListVolumes: Could not detach volume %s\n",
2375 pntr->volid = volid;
2376 /*just volids are needed */
2382 ttc = (struct volser_trans *)0;
2385 volumeInfo->volEntries_len += 1;
2386 if ((allocSize - volumeInfo->volEntries_len) < 5) {
2387 /*running out of space, allocate more space */
2388 allocSize = (allocSize * 3) / 2;
2390 (volintInfo *) realloc((char *)volumeInfo->volEntries_val,
2391 allocSize * sizeof(volintInfo));
2394 VDetachVolume(&error, tv);
2399 ttc = (struct volser_trans *)0;
2402 return VOLSERNO_MEMORY;
2404 volumeInfo->volEntries_val = pntr; /* point to new block */
2405 /* set pntr to the right position */
2406 pntr = volumeInfo->volEntries_val + volumeInfo->volEntries_len;
2412 VDetachVolume(&error, tv);
2417 ttc = (struct volser_trans *)0;
2419 GetNextVol(dirp, volname, &volid);
2429 /*------------------------------------------------------------------------
2430 * EXPORTED SAFSVolXListVolumes
2433 * Returns all the volumes on partition a_partID. If a_flags
2434 * is set to 1, then all the relevant extended volume information
2438 * a_rxCidP : Pointer to the Rx call we're performing.
2439 * a_partID : Partition for which we want the extended list.
2440 * a_flags : Various flags.
2441 * a_volumeXInfoP : Ptr to the extended info blob.
2444 * 0 Successful operation
2445 * VOLSERILLEGAL_PARTITION if we got a bogus partition ID
2446 * VOLSERNO_MEMORY if we ran out of memory allocating
2450 * Nothing interesting.
2454 *------------------------------------------------------------------------*/
2457 SAFSVolXListVolumes(a_rxCidP, a_partID, a_flags, a_volumeXInfoP)
2458 struct rx_call *a_rxCidP;
2461 volXEntries *a_volumeXInfoP;
2465 code = VolXListVolumes(a_rxCidP, a_partID, a_flags, a_volumeXInfoP);
2466 osi_auditU(a_rxCidP, VS_XLstVolEvent, code, AUD_END);
2471 VolXListVolumes(a_rxCidP, a_partID, a_flags, a_volumeXInfoP)
2472 struct rx_call *a_rxCidP;
2475 volXEntries *a_volumeXInfoP;
2477 { /*SAFSVolXListVolumes */
2479 volintXInfo *xInfoP; /*Ptr to the extended vol info */
2480 register struct Volume *tv; /*Volume ptr */
2481 struct DiskPartition *partP; /*Ptr to partition */
2482 struct volser_trans *ttc; /*Volume transaction ptr */
2483 afs_int32 allocSize = 1000; /*To be changed to a larger figure */
2484 char pname[9], volname[20]; /*Partition, volume names */
2485 afs_int32 error = 0; /*Return code */
2486 DIR *dirp; /*Partition directory ptr */
2487 afs_int32 volid; /*Current volume ID */
2488 struct VolumeDiskData *volDiskDataP; /*Ptr to on-disk volume data */
2489 int numStatBytes; /*Num stat bytes to copy per volume */
2493 * Allocate a large array of extended volume info structures, then
2494 * set it up for action.
2496 a_volumeXInfoP->volXEntries_val =
2497 (volintXInfo *) malloc(allocSize * sizeof(volintXInfo));
2498 xInfoP = a_volumeXInfoP->volXEntries_val;
2499 a_volumeXInfoP->volXEntries_len = 0;
2502 * If the partition name we've been given is bad, bogue out.
2504 if (GetPartName(a_partID, pname))
2505 return (VOLSERILLEGAL_PARTITION);
2508 * Open the directory representing the given AFS parttion. If we can't
2511 if (!(partP = VGetPartition(pname, 0)))
2512 return VOLSERILLEGAL_PARTITION;
2513 dirp = opendir(VPartitionPath(partP));
2515 return (VOLSERILLEGAL_PARTITION);
2518 * Sweep through the partition directory, acting on each entry. First,
2519 * of course, figure out how many stat bytes to copy out of each volume.
2522 4 * ((2 * VOLINT_STATS_NUM_RWINFO_FIELDS) +
2523 (4 * VOLINT_STATS_NUM_TIME_FIELDS));
2524 strcpy(volname, "");
2525 while (strcmp(volname, "EOD")) {
2526 ttc = (struct volser_trans *)0; /*New one for each pass */
2527 tv = (Volume *) 0; /*Volume not yet attached */
2530 * If this is not a volume, move on to the next entry in the
2531 * partition's directory.
2533 if (!strcmp(volname, "")) {
2534 GetNextVol(dirp, volname, &volid);
2540 * Full info about the volume desired. Poll to make sure the
2541 * client doesn't time out, then start up a new transaction.
2544 ttc = NewTrans(volid, a_partID);
2547 * Couldn't get a transaction on this volume; let our caller
2550 xInfoP->status = VBUSY;
2551 xInfoP->volid = volid;
2556 * Attach the volume, give up on this volume if we can't.
2558 tv = VAttachVolumeByName(&error, pname, volname, V_READONLY);
2560 xInfoP->status = 0; /*things are messed up */
2561 strcpy(xInfoP->name, volname);
2562 xInfoP->volid = volid;
2563 Log("1 Volser: XListVolumes: Could not attach volume %u\n",
2569 * Also bag out on this volume if it's been marked as needing a
2570 * salvage or to-be-destroyed.
2572 volDiskDataP = &(tv->header->diskstuff);
2573 if (volDiskDataP->needsSalvaged) {
2575 strcpy(xInfoP->name, volname);
2576 xInfoP->volid = volid;
2577 Log("1 Volser: XListVolumes: Volume %u needs to be salvaged\n", volid);
2581 if (volDiskDataP->destroyMe == DESTROY_ME)
2585 * Pull out the desired info and stuff it into the area we'll be
2586 * returning to our caller.
2588 strcpy(xInfoP->name, volDiskDataP->name);
2589 xInfoP->volid = volDiskDataP->id;
2590 xInfoP->type = volDiskDataP->type;
2591 xInfoP->backupID = volDiskDataP->backupId;
2592 xInfoP->parentID = volDiskDataP->parentId;
2593 xInfoP->cloneID = volDiskDataP->cloneId;
2594 xInfoP->status = VOK;
2595 xInfoP->copyDate = volDiskDataP->copyDate;
2596 xInfoP->inUse = volDiskDataP->inUse;
2597 xInfoP->creationDate = volDiskDataP->creationDate;
2598 xInfoP->accessDate = volDiskDataP->accessDate;
2599 xInfoP->updateDate = volDiskDataP->updateDate;
2600 xInfoP->backupDate = volDiskDataP->backupDate;
2601 now = FT_ApproxTime();
2602 if (now - volDiskDataP->dayUseDate > OneDay)
2605 xInfoP->dayUse = volDiskDataP->dayUse;
2606 xInfoP->filecount = volDiskDataP->filecount;
2607 xInfoP->maxquota = volDiskDataP->maxquota;
2608 xInfoP->size = volDiskDataP->diskused;
2611 * Copy out the stat fields in a single operation.
2613 memcpy((char *)&(xInfoP->stat_reads[0]),
2614 (char *)&(volDiskDataP->stat_reads[0]), numStatBytes);
2617 * We're done copying. Detach the volume and iterate.
2619 VDetachVolume(&error, tv);
2623 strcpy(xInfoP->name, volname);
2624 Log("1 Volser: XListVolumes: Could not detach volume %s\n",
2628 } /*Full contents desired */
2631 * Just volume IDs are needed.
2633 xInfoP->volid = volid;
2637 * Drop the transaction we have for this volume.
2641 ttc = (struct volser_trans *)0;
2645 * Bump the pointer in the data area we're building, along with
2646 * the count of the number of entries it contains.
2649 (a_volumeXInfoP->volXEntries_len)++;
2650 if ((allocSize - a_volumeXInfoP->volXEntries_len) < 5) {
2652 * We're running out of space in the area we've built. Grow it.
2654 allocSize = (allocSize * 3) / 2;
2655 xInfoP = (volintXInfo *)
2656 realloc((char *)a_volumeXInfoP->volXEntries_val,
2657 (allocSize * sizeof(volintXInfo)));
2658 if (xInfoP == NULL) {
2660 * Bummer, no memory. Bag it, tell our caller what went wrong.
2663 VDetachVolume(&error, tv);
2668 ttc = (struct volser_trans *)0;
2671 return (VOLSERNO_MEMORY);
2675 * Memory reallocation worked. Correct our pointers so they
2676 * now point to the new block and the current open position within
2679 a_volumeXInfoP->volXEntries_val = xInfoP;
2681 a_volumeXInfoP->volXEntries_val +
2682 a_volumeXInfoP->volXEntries_len;
2684 /*Need more space */
2687 * Detach our current volume and the transaction on it, then move on
2688 * to the next volume in the partition directory.
2691 VDetachVolume(&error, tv);
2696 ttc = (struct volser_trans *)0;
2698 GetNextVol(dirp, volname, &volid);
2699 } /*Sweep through the partition directory */
2702 * We've examined all entries in the partition directory. Close it,
2703 * delete our transaction (if any), and go home happy.
2710 } /*SAFSVolXListVolumes */
2712 /*this call is used to monitor the status of volser for debugging purposes.
2713 *information about all the active transactions is returned in transInfo*/
2715 SAFSVolMonitor(acid, transInfo)
2716 struct rx_call *acid;
2717 transDebugEntries *transInfo;
2721 code = VolMonitor(acid, transInfo);
2722 osi_auditU(acid, VS_MonitorEvent, code, AUD_END);
2727 VolMonitor(acid, transInfo)
2728 struct rx_call *acid;
2729 transDebugEntries *transInfo;
2731 transDebugInfo *pntr;
2732 afs_int32 allocSize = 50;
2733 struct volser_trans *tt, *allTrans;
2735 transInfo->transDebugEntries_val =
2736 (transDebugInfo *) malloc(allocSize * sizeof(transDebugInfo));
2737 pntr = transInfo->transDebugEntries_val;
2738 transInfo->transDebugEntries_len = 0;
2739 allTrans = TransList();
2740 if (allTrans == (struct volser_trans *)0)
2741 return 0; /*no active transactions */
2742 for (tt = allTrans; tt; tt = tt->next) { /*copy relevant info into pntr */
2743 pntr->tid = tt->tid;
2744 pntr->time = tt->time;
2745 pntr->creationTime = tt->creationTime;
2746 pntr->returnCode = tt->returnCode;
2747 pntr->volid = tt->volid;
2748 pntr->partition = tt->partition;
2749 pntr->iflags = tt->iflags;
2750 pntr->vflags = tt->vflags;
2751 pntr->tflags = tt->tflags;
2752 strcpy(pntr->lastProcName, tt->lastProcName);
2753 pntr->callValid = 0;
2754 if (tt->rxCallPtr) { /*record call related info */
2755 pntr->callValid = 1;
2756 pntr->readNext = tt->rxCallPtr->rnext;
2757 pntr->transmitNext = tt->rxCallPtr->tnext;
2758 pntr->lastSendTime = tt->rxCallPtr->lastSendTime;
2759 pntr->lastReceiveTime = tt->rxCallPtr->lastReceiveTime;
2762 transInfo->transDebugEntries_len += 1;
2763 if ((allocSize - transInfo->transDebugEntries_len) < 5) { /*alloc some more space */
2764 allocSize = (allocSize * 3) / 2;
2766 (transDebugInfo *) realloc((char *)transInfo->
2767 transDebugEntries_val,
2769 sizeof(transDebugInfo));
2770 transInfo->transDebugEntries_val = pntr;
2772 transInfo->transDebugEntries_val +
2773 transInfo->transDebugEntries_len;
2774 /*set pntr to right position */
2783 SAFSVolSetIdsTypes(acid, atid, name, type, pId, cloneId, backupId)
2784 struct rx_call *acid;
2785 afs_int32 type, pId, cloneId, backupId, atid;
2790 code = VolSetIdsTypes(acid, atid, name, type, pId, cloneId, backupId);
2791 osi_auditU(acid, VS_SetIdTyEvent, code, AUD_LONG, atid, AUD_STR, name,
2792 AUD_STR, type, AUD_LONG, pId, AUD_LONG, cloneId, AUD_LONG,
2798 VolSetIdsTypes(acid, atid, name, type, pId, cloneId, backupId)
2799 struct rx_call *acid;
2800 afs_int32 type, pId, cloneId, backupId, atid;
2804 afs_int32 error = 0;
2805 register struct volser_trans *tt;
2806 char caller[MAXKTCNAMELEN];
2808 if (strlen(name) > 31)
2809 return VOLSERBADNAME;
2810 if (!afsconf_SuperUser(tdir, acid, caller))
2811 return VOLSERBAD_ACCESS; /*not a super user */
2812 /* find the trans */
2813 tt = FindTrans(atid);
2816 if (tt->vflags & VTDeleted) {
2817 Log("1 Volser: VolSetIds: volume %u has been deleted \n", tt->volid);
2821 strcpy(tt->lastProcName, "SetIdsTypes");
2822 tt->rxCallPtr = acid;
2826 V_backupId(tv) = backupId;
2827 V_cloneId(tv) = cloneId;
2828 V_parentId(tv) = pId;
2829 strcpy((&V_disk(tv))->name, name);
2830 VUpdateVolume(&error, tv);
2832 Log("1 Volser: SetIdsTypes: VUpdate failed code %d\n", error);
2836 tt->rxCallPtr = (struct rx_call *)0;
2837 if (TRELE(tt) && !error)
2838 return VOLSERTRELE_ERROR;
2842 tt->rxCallPtr = (struct rx_call *)0;
2843 if (TRELE(tt) && !error)
2844 return VOLSERTRELE_ERROR;
2849 SAFSVolSetDate(acid, atid, cdate)
2850 struct rx_call *acid;
2851 afs_int32 atid, cdate;
2855 code = VolSetDate(acid, atid, cdate);
2856 osi_auditU(acid, VS_SetDateEvent, code, AUD_LONG, atid, AUD_LONG, cdate,
2862 VolSetDate(acid, atid, cdate)
2863 struct rx_call *acid;
2864 afs_int32 atid, cdate;
2867 afs_int32 error = 0;
2868 register struct volser_trans *tt;
2869 char caller[MAXKTCNAMELEN];
2871 if (!afsconf_SuperUser(tdir, acid, caller))
2872 return VOLSERBAD_ACCESS; /*not a super user */
2873 /* find the trans */
2874 tt = FindTrans(atid);
2877 if (tt->vflags & VTDeleted) {
2878 Log("1 Volser: VolSetDate: volume %u has been deleted \n", tt->volid);
2882 strcpy(tt->lastProcName, "SetDate");
2883 tt->rxCallPtr = acid;
2886 V_creationDate(tv) = cdate;
2887 VUpdateVolume(&error, tv);
2889 Log("1 Volser: SetDate: VUpdate failed code %d\n", error);
2893 tt->rxCallPtr = (struct rx_call *)0;
2894 if (TRELE(tt) && !error)
2895 return VOLSERTRELE_ERROR;
2899 tt->rxCallPtr = (struct rx_call *)0;
2900 if (TRELE(tt) && !error)
2901 return VOLSERTRELE_ERROR;
2905 #ifdef AFS_NAMEI_ENV
2907 * Inode number format (from namei_ops.c):
2908 * low 26 bits - vnode number - all 1's if volume special file.
2910 * next 3 bits spare (0's)
2911 * high 32 bits - uniquifier (regular) or type if spare
2913 #define NAMEI_VNODEMASK 0x003ffffff
2914 #define NAMEI_TAGMASK 0x7
2915 #define NAMEI_TAGSHIFT 26
2916 #define NAMEI_UNIQMASK 0xffffffff
2917 #define NAMEI_UNIQSHIFT 32
2918 #define NAMEI_INODESPECIAL ((Inode)NAMEI_VNODEMASK)
2919 #define NAMEI_VNODESPECIAL NAMEI_VNODEMASK
2920 #endif /* AFS_NAMEI_ENV */
2923 SAFSVolConvertROtoRWvolume(acid, partId, volumeId)
2924 struct rx_call *acid;
2928 #if defined(AFS_NAMEI_ENV) && !defined(AFS_NT40_ENV)
2932 afs_int32 error = 0;
2935 char caller[MAXKTCNAMELEN];
2936 char headername[16];
2939 struct VolumeDiskHeader h;
2943 struct DiskPartition *dp;
2945 if (!afsconf_SuperUser(tdir, acid, caller))
2946 return VOLSERBAD_ACCESS; /*not a super user */
2947 if (GetPartName(partId, pname))
2948 return VOLSERILLEGAL_PARTITION;
2949 dirp = opendir(pname);
2951 return VOLSERILLEGAL_PARTITION;
2952 strcpy(volname, "");
2954 while (strcmp(volname, "EOD") && !found) { /*while there are more volumes in the partition */
2955 GetNextVol(dirp, volname, &volid);
2956 if (strcmp(volname, "")) { /* its a volume */
2957 if (volid == volumeId)
2963 (void)afs_snprintf(headername, sizeof headername, VFORMAT, volumeId);
2964 (void)afs_snprintf(opath, sizeof opath, "%s/%s", pname, headername);
2965 fd = open(opath, O_RDONLY);
2967 Log("1 SAFS_VolConvertROtoRWvolume: Couldn't open header for RO-volume %lu.\n", volumeId);
2970 if (read(fd, &h, sizeof(h)) != sizeof(h)) {
2971 Log("1 SAFS_VolConvertROtoRWvolume: Couldn't read header for RO-volume %lu.\n", volumeId);
2976 FSYNC_askfs(volumeId, pname, FSYNC_RESTOREVOLUME, 0);
2978 for (dp = DiskPartitionList; dp && strcmp(dp->name, pname);
2981 Log("1 SAFS_VolConvertROtoRWvolume: Couldn't find DiskPartition for %s\n", pname);
2984 ino = namei_MakeSpecIno(h.parent, VI_LINKTABLE);
2985 IH_INIT(ih, dp->device, h.parent, ino);
2987 error = namei_ConvertROtoRWvolume(ih, volumeId);
2991 h.volumeInfo_hi = h.id;
2992 h.smallVnodeIndex_hi = h.id;
2993 h.largeVnodeIndex_hi = h.id;
2994 h.linkTable_hi = h.id;
2995 (void)afs_snprintf(headername, sizeof headername, VFORMAT, h.id);
2996 (void)afs_snprintf(npath, sizeof npath, "%s/%s", pname, headername);
2997 fd = open(npath, O_CREAT | O_EXCL | O_RDWR, 0644);
2999 Log("1 SAFS_VolConvertROtoRWvolume: Couldn't create header for RW-volume %lu.\n", h.id);
3002 if (write(fd, &h, sizeof(h)) != sizeof(h)) {
3003 Log("1 SAFS_VolConvertROtoRWvolume: Couldn't write header for RW-volume %lu.\n", h.id);
3008 if (unlink(opath) < 0) {
3009 Log("1 SAFS_VolConvertROtoRWvolume: Couldn't unlink RO header, error = %d\n", error);
3011 FSYNC_askfs(volumeId, pname, FSYNC_DONE, 0);
3012 FSYNC_askfs(h.id, pname, FSYNC_ON, 0);
3014 #else /* AFS_NAMEI_ENV */
3016 #endif /* AFS_NAMEI_ENV */
3020 SAFSVolGetSize(acid, fromTrans, fromDate, size)
3021 struct rx_call *acid;
3022 afs_int32 fromTrans;
3024 register struct volintSize *size;
3027 register struct volser_trans *tt;
3028 char caller[MAXKTCNAMELEN];
3030 if (!afsconf_SuperUser(tdir, acid, caller))
3031 return VOLSERBAD_ACCESS; /*not a super user */
3032 tt = FindTrans(fromTrans);
3035 if (tt->vflags & VTDeleted) {
3039 strcpy(tt->lastProcName, "GetSize");
3040 tt->rxCallPtr = acid;
3041 code = SizeDumpVolume(acid, tt->volume, fromDate, 1, size); /* measure volume's data */
3042 tt->rxCallPtr = (struct rx_call *)0;
3044 return VOLSERTRELE_ERROR;
3046 /* osi_auditU(acid, VS_DumpEvent, code, AUD_LONG, fromTrans, AUD_END); */
3050 /* GetPartName - map partid (a decimal number) into pname (a string)
3051 * Since for NT we actually want to return the drive name, we map through the
3055 GetPartName(afs_int32 partid, char *pname)
3060 strcpy(pname, "/vicep");
3061 pname[6] = 'a' + partid;
3064 } else if (partid < VOLMAXPARTS) {
3065 strcpy(pname, "/vicep");
3067 pname[6] = 'a' + (partid / 26);
3068 pname[7] = 'a' + (partid % 26);