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
11 * Implementation of the volume operations used by the AFS user
16 * --------------------- Required definitions ---------------------
18 #include <afsconfig.h>
19 #include <afs/param.h>
22 #include "uss_vol.h" /*Interface to this module */
23 #include "uss_common.h" /*Common definitions */
24 #include "uss_procs.h" /*Defs from procs module */
25 #include "uss_fs.h" /*CacheManager ops */
34 #include <afs/com_err.h>
35 #include <afs/vlserver.h>
36 #include <afs/vldbint.h>
38 #include <afs/cellconfig.h>
39 #include <rx/rx_globals.h>
40 #include <afs/volser.h>
41 #include <afs/volint.h>
43 #include <afs/afsutil.h>
49 * ---------------------- Private definitions ---------------------
52 #undef USS_VOL_DB_SHOW_OVERRIDES
56 * --------------------- Exported definitions ---------------------
59 * The Volume Server interface imports the Ubik connection
60 * structure to use, expecting it to be named "cstruct". This
61 * is why we have two names here. Thus, the UV_CreateVolume()
62 * will work and we can avoid nasty little core dumps.
64 struct ubik_client *uconn_vldbP; /*Ubik connection struct */
65 struct ubik_client *cstruct; /*Required name for above */
68 * ------------------------ Private globals -----------------------
70 static int initDone = 0; /*Module initialized? */
71 static int NoAuthFlag = 0; /*Use -noauth? */
72 static struct rx_connection
73 *serverconns[VLDB_MAXSERVERS]; /*Connection(s) to VLDB
77 /*-----------------------------------------------------------------------
78 * static InitThisModule
81 * Set up this module, namely set up all the client state for
82 * dealing with the Volume Location Server(s), including
83 * network connections.
86 * a_noAuthFlag : Do we need authentication?
87 * a_confDir : Configuration directory to use.
88 * a_cellName : Cell we want to talk to.
91 * 0 if everything went fine, or
92 * lower-level error code otherwise.
95 * This routine will only be called once.
99 *------------------------------------------------------------------------*/
102 InitThisModule(int a_noAuthFlag, char *a_confDir, char *a_cellName)
103 { /*InitThisModule */
105 static char rn[] = "uss_vol:InitThisModule";
107 register afs_int32 code; /*Return code */
108 struct afsconf_dir *tdir; /*Ptr to conf dir info */
109 struct afsconf_cell info; /*Info about chosen cell */
110 struct ktc_principal sname; /*Service name */
111 struct ktc_token ttoken; /*Service ticket */
112 afs_int32 scIndex; /*Chosen security index */
113 struct rx_securityClass *sc; /*Generated security object */
114 afs_int32 i; /*Loop index */
117 * Only once, guys, will 'ya?
121 printf("[%s] Called multiple times!\n", rn);
122 #endif /* USS_VOL_DB */
127 * Set up our Rx environment.
130 printf("[%s] Initializing Rx environment\n", rn);
131 #endif /* USS_VOL_DB */
134 fprintf(stderr, "%s: Couldn't initialize Rx.\n", uss_whoami);
137 rx_SetRxDeadTime(50);
140 * Find out all about our configuration.
143 printf("[%s] Handling configuration info\n", rn);
144 #endif /* USS_VOL_DB */
145 tdir = afsconf_Open(a_confDir);
147 fprintf(stderr, "%s: Couldn't open configuration directory (%s).\n",
148 uss_whoami, a_confDir);
151 code = afsconf_GetCellInfo(tdir, a_cellName, AFSCONF_VLDBSERVICE, &info);
153 printf("%s: Can't find VLDB server(s) for cell %s\n", uss_whoami,
158 printf("[%s] Getting tickets if needed\n", rn);
159 #endif /* USS_VOL_DB */
162 * We don't need tickets for unauthenticated connections.
164 strcpy(sname.cell, info.name);
165 sname.instance[0] = 0;
166 strcpy(sname.name, "afs");
167 code = ktc_GetToken(&sname, &ttoken, sizeof(ttoken), NULL);
170 "%s: Couldn't get AFS tokens, running unauthenticated.\n",
175 * We got a ticket, go for an authenticated connection.
177 if (ttoken.kvno >= 0 && ttoken.kvno <= 256)
178 scIndex = 2; /*Kerberos */
180 fprintf(stderr, "%s: Funny kvno (%d) in ticket, proceeding\n",
181 uss_whoami, ttoken.kvno);
185 } /*Authentication desired */
190 * Generate the appropriate security object for the connection.
193 printf("[%s] Generating Rx security object\n", rn);
194 #endif /* USS_VOL_DB */
197 sc = (struct rx_securityClass *)
198 rxnull_NewClientSecurityObject();
205 sc = (struct rx_securityClass *)
206 rxkad_NewClientSecurityObject(rxkad_clear, &ttoken.sessionKey,
207 ttoken.kvno, ttoken.ticketLen,
213 * Tell UV module about default authentication.
216 printf("[%s] Setting UV security: obj 0x%x, index %d\n", rn, sc, scIndex);
217 #endif /* USS_VOL_DB */
218 UV_SetSecurity(sc, scIndex);
219 if (info.numServers > VLDB_MAXSERVERS) {
220 fprintf(stderr, "%s: info.numServers=%d (> VLDB_MAXSERVERS=%d)\n",
221 uss_whoami, info.numServers, VLDB_MAXSERVERS);
226 * Connect to each VLDB server for the chosen cell.
228 for (i = 0; i < info.numServers; i++) {
231 ("[%s] Connecting to VLDB server 0x%x, port %d, service id %d\n",
232 rn, info.hostAddr[i].sin_addr.s_addr, info.hostAddr[i].sin_port,
234 #endif /* USS_VOL_DB */
236 rx_NewConnection(info.hostAddr[i].sin_addr.s_addr,
237 info.hostAddr[i].sin_port, USER_SERVICE_ID, sc,
242 * Set up to execute Ubik transactions on the VLDB.
245 printf("[%s] Initializing Ubik interface\n", rn);
246 #endif /* USS_VOL_DB */
247 code = ubik_ClientInit(serverconns, &uconn_vldbP);
249 fprintf(stderr, "%s: Ubik client init failed.\n", uss_whoami);
253 printf("[%s] VLDB ubik connection structure at 0x%x\n", rn, uconn_vldbP);
254 #endif /* USS_VOL_DB */
257 * Place the ubik VLDB connection structure in its advertised
260 cstruct = uconn_vldbP;
268 } /*InitThisModule */
271 /*-----------------------------------------------------------------------
272 * static HostIDToHostName
275 * Given a host ID (in network byte order), figure out the
276 * corresponding host name.
279 * a_hostID : Host ID in network byte order.
280 * a_hostName : Ptr to host name buffer.
286 * This routine simply calls the hostutil_GetNameByINet()
287 * function exported by the utility library (util.a).
291 *------------------------------------------------------------------------*/
294 HostIDToHostName(afs_int32 a_hostID, char *a_hostName)
295 { /*HostIDToHostName */
297 strcpy(a_hostName, hostutil_GetNameByINet(a_hostID));
299 } /*HostIDToHostName */
302 /*-----------------------------------------------------------------------
303 * static PartIDToPartName
306 * Given a partition ID (in network byte order), figure out the
307 * corresponding partition name.
310 * a_partID : Partition ID in network byte order.
311 * a_partName : Ptr to partition name buffer.
314 * 0 if everything went well, or
315 * -1 if the given partition ID couldn't be translated.
318 * Nothing interesting.
322 *------------------------------------------------------------------------*/
325 PartIDToPartName(afs_int32 a_partID, char *a_partName)
326 { /*PartIDToPartName */
328 static char rn[] = "PartIDToPartName";
331 printf("[%s] Translating partition id %d to its name\n", rn, a_partID);
332 #endif /* USS_VOL_DB */
334 if ((a_partID < 0) || (a_partID > VOLMAXPARTS))
338 strcpy(a_partName, "/vicep");
339 a_partName[6] = a_partID + 'a';
340 a_partName[7] = '\0';
342 strcpy(a_partName, "/vicep");
344 a_partName[6] = 'a' + (a_partID / 26);
345 a_partName[7] = 'a' + (a_partID % 26);
346 a_partName[8] = '\0';
350 printf("[%s] Translation for part ID %d is '%s'\n", rn, a_partID,
352 #endif /* USS_VOL_DB */
355 } /*PartIDToPartName */
358 /*------------------------------------------------------------------------
359 * EXPORTED uss_Vol_GetServer
362 * Nothing interesting.
366 *------------------------------------------------------------------------*/
369 uss_vol_GetServer(char *a_name)
370 { /*uss_vol_GetServer */
372 register struct hostent *th;
374 afs_int32 b1, b2, b3, b4;
375 register afs_int32 code;
377 code = sscanf(a_name, "%d.%d.%d.%d", &b1, &b2, &b3, &b4);
380 * Parsed as 128.2.9.4, or similar; return it in network
381 * byte order (128 in byte 0).
383 addr = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
387 th = gethostbyname(a_name);
390 memcpy(&addr, th->h_addr, sizeof(addr));
393 } /*uss_vol_GetServer */
395 /* XXX - This function is unused, and could be deleted */
397 /*------------------------------------------------------------------------
398 * static GetVolumeType
401 * Translate the given char string representing a volume type to the
402 * numeric representation.
405 * a_type : Char string volume type.
408 * One of ROVOL, RWVOL, BACKVOL, or -1 on failure.
411 * Nothing interesting.
415 *------------------------------------------------------------------------*/
418 GetVolumeType(char *a_type)
421 if (!strcmp(a_type, "ro"))
423 else if (!strcmp(a_type, "rw"))
425 else if (!strcmp(a_type, "bk"))
433 /*------------------------------------------------------------------------
434 * EXPORTED uss_Vol_GetPartitionID
437 * It is assumed that partition names may begin with ``/vicep''.
441 *------------------------------------------------------------------------*/
444 uss_vol_GetPartitionID(char *a_name)
445 { /*uss_vol_GetPartitionID */
455 * Numbers go straight through.
457 if (tc >= '0' && tc <= '9') {
458 return (atoi(a_name));
462 * Otherwise, check for vicepa or /vicepa, or just plain "a"
465 if (strlen(a_name) <= 2) {
466 strcpy(ascii, a_name);
467 } else if (!strncmp(a_name, "/vicep", 6)) {
468 strncpy(ascii, a_name + 6, 2);
469 } else if (!strncmp(a_name, "vicep", 5)) {
470 strncpy(ascii, a_name + 5, 2);
475 * Now, partitions are named /vicepa ... /vicepz, /vicepaa, /vicepab,
476 * .../vicepzz, and are numbered from 0. Do the appropriate conversion.
480 * Single-char name, 0..25
482 if (ascii[0] < 'a' || ascii[0] > 'z')
483 return (-1); /* wrongo */
484 return (ascii[0] - 'a');
487 * Two-char name, 26 .. <whatever>
489 if (ascii[0] < 'a' || ascii[0] > 'z')
491 if (ascii[1] < 'a' || ascii[1] > 'z')
493 return ((ascii[0] - 'a') * 26 + (ascii[1] - 'a') + 26);
495 } /*uss_vol_GetPartitionID */
498 /*-----------------------------------------------------------------------
499 * static CheckDoubleMount
502 * Make sure we're not trying to mount a volume in the same place
506 * a_mp : Mountpoint pathname to check.
507 * a_oldmp : Ptr to buffer into which the old value of the
508 * mountpoint is placed (if any).
511 * 0 if the volume was not previously mounted.
512 * uss_procs_ANCIENT if there was already a mountpoint AND the
513 * user was already recorded in the password
515 * uss_procs_YOUNG if there was a mountpoint for the user taken
516 * from the directory pool, yet the user was not
517 * yet in the password file.
520 * Nothing interesting.
523 * May fill in the a_oldmp buffer with the value of the old
525 *------------------------------------------------------------------------*/
528 CheckDoubleMount(char *a_mp, char *a_oldmp)
529 { /*CheckDoubleMount */
532 static char rn[] = "uss_vol:CheckDoubleMount";
534 int start, len, mlen, tlen;
539 pws = getpwuid(atoi(uss_Uid));
542 * User exists in the password file, so they've been fully
543 * created and integrated. Return the ``ancient'' mountpoint.
545 strcpy(a_oldmp, pws->pw_dir);
546 return (uss_procs_ANCIENT);
551 * $AUTO used. Search among the possible directories.
553 len = strlen(uss_Auto);
555 while (strncmp(&a_mp[i], uss_Auto, len)) {
556 a_oldmp[i] = a_mp[i];
557 if (++i > (mlen - len)) {
562 if ((start = i) != -1) {
564 * $AUTO used in mountpoint.
566 for (i = 0; i < uss_NumGroups; i++) {
568 * Copy in the base and tail components.
570 tlen = strlen(uss_DirPool[i]);
571 strncpy(&a_oldmp[start], uss_DirPool[i], tlen);
572 strcpy(&a_oldmp[start + tlen], &a_mp[start + len]);
574 printf("%s: Checking '%s' for mount point\n", rn, a_oldmp);
575 #endif /* USS_VOL_DB */
576 if (lstat(a_oldmp, &stbuf) == 0) /*mp exists */
577 if (strcmp(a_oldmp, a_mp))
578 /* and is different */
580 * The old mount point exists and is different
581 * from the current one, so return the fact
582 * that we have a ``young'' mountpoint.
584 return (uss_procs_YOUNG);
585 } /*Check each $AUTO directory */
589 /*$AUTO has been used */
591 * No luck finding the old mount point, so we just return that
592 * this is the first time we've seen this volume.
596 } /*CheckDoubleMount */
599 /*------------------------------------------------------------------------
600 * EXPORTED uss_vol_CreateVol
603 * Called from the code generated by the uss grammar.
607 *------------------------------------------------------------------------*/
610 uss_vol_CreateVol(char *a_volname, char *a_server, char *a_partition,
611 char *a_quota, char *a_mpoint, char *a_owner,
613 { /*uss_vol_CreateVol */
615 static char rn[] = "uss_vol_CreateVol"; /*Routine name */
617 afs_int32 pname; /*Partition name */
618 afs_int32 volid, code; /*Volume ID, return code */
619 afs_int32 saddr; /*Socket info for server */
620 int VolExistFlag = 0; /*Does the volume exist? */
621 int mpExistFlag = 0; /*Does the mountpoint exist? */
622 char *Oldmpoint = NULL; /*Old mountpoint name, if any */
623 char tmp_str[uss_MAX_SIZE]; /*Useful string buffer */
624 int o; /*Owner's user id */
625 char userinput[64]; /*User's input */
626 struct uss_subdir *new_dir; /*Used to remember original ACL */
629 * Don't do anything if there's already a problem.
635 fprintf(stderr, "%s:uss_vol_CreateVol params:\n", rn);
637 "%s: volname '%s', server '%s', partition '%s', quota '%s', mpoint '%s', owner '%s', acl '%s'\n",
638 rn, a_volname, a_server, a_partition, a_quota, a_mpoint, a_owner,
640 #endif /* USS_VOL_DB */
643 * All of the parameters passed in are taken from the template
644 * file. Override these values if the user has explicitly set
645 * them, namely if the uss commons have non-null strings.
647 if (uss_Server[0] != '\0') {
648 #ifdef USS_VOL_DB_SHOW_OVERRIDES
651 "%s: Overriding server field: template value is '%s', overridden to '%s'\n",
652 rn, a_server, uss_Server);
653 #endif /* USS_VOL_DB_SHOW_OVERRIDES */
654 a_server = uss_Server;
657 if (uss_Partition[0] != '\0') {
658 #ifdef USS_VOL_DB_SHOW_OVERRIDES
661 "%s: Overriding partition field: template value is '%s', overridden to '%s'\n",
662 rn, a_partition, uss_Partition);
663 #endif /* USS_VOL_DB_SHOW_OVERRIDES */
664 a_partition = uss_Partition;
667 if (uss_MountPoint[0] != '\0') {
668 #ifdef USS_VOL_DB_SHOW_OVERRIDES
671 "%s: overriding mountpoint field: template value is '%s', overridden to '%s'\n",
672 rn, a_mpoint, uss_MountPoint);
673 #endif /* USS_VOL_DB_SHOW_OVERRIDES */
674 a_mpoint = uss_MountPoint;
676 #ifdef USS_VOL_DB_SHOW_OVERRIDES
677 printf("%s: Params after overrides:\n", uss_whoami);
679 ("%s: volname '%s', server '%s', partition '%s', quota '%s', mpoint '%s', owner '%s', acl '%s'\n",
680 uss_whoami, a_volname, a_server, a_partition, a_quota, a_mpoint,
682 #endif /* USS_VOL_DB_SHOW_OVERRIDES */
686 "Creating volume '%s' on server '%s', partition '%s'\n",
687 a_volname, a_server, a_partition);
689 saddr = uss_vol_GetServer(a_server);
691 uss_procs_PrintErr(line,
692 "File server '%s' not found in config info\n",
696 pname = uss_vol_GetPartitionID(a_partition);
698 uss_procs_PrintErr(line, "Couldn't interpret partition name '%s'\n",
704 * Make sure our VLDB connection(s) is/are set up before actually
705 * trying to perform a volume creation creation.
708 code = InitThisModule(NoAuthFlag, uss_ConfDir, uss_Cell);
710 afs_com_err(uss_whoami, code,
711 "while inititializing VLDB connection(s)\n");
715 /*Initialize VLDB connection(s) */
718 printf("%s: Creating volume on srv 0x%x, part %d, vol name '%s'\n",
719 rn, saddr, pname, a_volname);
720 #endif /* USS_VOL_DB */
721 code = UV_CreateVolume(saddr, pname, a_volname, &volid);
723 if (code == VL_NAMEEXIST) {
726 "%s: Warning; Volume '%s' exists, using existing one.\n",
727 uss_whoami, a_volname);
730 * We should get the volid here if we want to use it, but
731 * we don't need it right now. What we DO need, though, is
732 * to ask our caller if it's OK to overwrite the user's files
733 * if they're pre-existing.
735 if (!uss_OverwriteThisOne) {
737 ("Overwrite files in pre-existing '%s' volume? [y, n]: ",
739 scanf("%s", userinput);
740 if ((userinput[0] == 'y') || (userinput[0] == 'Y')) {
741 printf("\t[Overwriting allowed]\n");
742 uss_OverwriteThisOne = 1;
744 printf("\t[Overwriting not permitted]\n");
745 } /*Overwriting not previously allowed */
746 } /*Volume already existed */
748 uss_procs_PrintErr(line,
749 "Couldn't create volume '%s' [error %d]: %s\n",
750 a_volname, code, strerror(errno));
752 } /*Failure was NOT because it already existed */
753 } /*UV_CreateVolume failed */
757 "\t[Dry run: Creating volume '%s' on '%s', partition '%s']\n",
758 a_volname, a_server, a_partition);
761 /* OK, we want to make sure we don't double-mount the volume.
762 * If the volume existed, it can be the case that it is
763 * already mounted somewhere else (because of $AUTO or others).
764 * Let's check for that. Note: we never enter this portion of
765 * the code if we're doing a dry run.
768 if ((Oldmpoint = (char *)malloc(strlen(a_mpoint) + 50)) == NULL) {
769 fprintf(stderr, "%s: No more memory!\n", uss_whoami);
773 mpExistFlag = CheckDoubleMount(a_mpoint, Oldmpoint);
774 if (mpExistFlag == uss_procs_ANCIENT) {
776 "%s:\t*** WARNING ***; This user (%s) is already in passwd file (or equivalent). IGNORED.\n",
777 uss_whoami, uss_User);
779 uss_syntax_err = 1; /*I know, I know, it's not a SYNTAX error */
783 if (mpExistFlag == uss_procs_YOUNG) {
785 "%s: Warning; Volume '%s' is already mounted on %s. Using the existing one.\n",
786 uss_whoami, a_volname, Oldmpoint);
787 a_mpoint = Oldmpoint;
791 if (mpExistFlag == 0) {
792 extern int local_Cell;
797 sprintf(tmp_str, "#%s.", a_volname);
799 sprintf(tmp_str, "#%s:%s.", uss_Cell, a_volname);
801 if (symlink(tmp_str, a_mpoint)) {
802 if (errno == EEXIST) {
804 "%s: Warning: Mount point '%s' already exists.\n",
805 uss_whoami, a_mpoint);
808 "%s: Can't mount volume '%s' on '%s': %s\n",
809 uss_whoami, a_volname, a_mpoint, strerror(errno));
813 } /*There was already something mounted there */
817 fprintf(stderr, "\t[Dry run: Mounting '%s' at '%s']\n", tmp_str,
822 /*Mount point didn't already exist */
824 * Set the volume disk quota.
827 if ((code = uss_acl_SetDiskQuota(a_mpoint, atoi(a_quota))))
832 "\t[Dry run: Setting disk quota for '%s' to %s blocks]\n",
836 /*Copy mpoint into $MTPT for others to use */
837 strcpy(uss_MountPoint, a_mpoint);
839 o = uss_procs_GetOwner(a_owner);
841 if (chown(a_mpoint, o, -1)) {
843 "%s: Can't chown() mountpoint '%s' to owner '%s' (uid %d): %s\n",
844 uss_whoami, a_mpoint, a_owner, o, strerror(errno));
852 "\t[Dry run: chown() mountpoint '%s' to be owned by user]\n",
857 * Set the ACL on the user's home directory so that, for the duration of
858 * the account creation, only the uss_AccountCreator has any rights on the
859 * files therein. Make sure to clear this ACL to remove anyone that might
860 * already be there due to volume creation defaults. We will set this ACL
861 * properly, as well as all ACLs of future subdirectories,as the very last
862 * thing we do to the new account.
864 new_dir = (struct uss_subdir *)malloc(sizeof(struct uss_subdir));
865 new_dir->previous = uss_currentDir;
866 new_dir->path = (char *)malloc(strlen(a_mpoint) + 1);
867 strcpy(new_dir->path, a_mpoint);
868 new_dir->finalACL = (char *)malloc(strlen(a_acl) + 1);
869 strcpy(new_dir->finalACL, a_acl);
870 uss_currentDir = new_dir;
871 sprintf(tmp_str, "%s %s all", a_mpoint, uss_AccountCreator);
878 fprintf(stderr, "Setting ACL: '%s'\n", tmp_str);
879 if (uss_acl_SetAccess(tmp_str, 1, 0))
883 fprintf(stderr, "\t[Dry run: uss_acl_SetAccess(%s)]\n", tmp_str);
886 } /*uss_vol_CreateVol */
889 /*------------------------------------------------------------------------
890 * EXPORTED uss_vol_DeleteVol
893 * Nothing interesting.
897 *------------------------------------------------------------------------*/
900 uss_vol_DeleteVol(char *a_volName, afs_int32 a_volID, char *a_servName,
901 afs_int32 a_servID, char *a_partName, afs_int32 a_partID)
902 { /*uss_vol_DeleteVol */
905 static char rn[] = "uss_vol_DeleteVol"; /*Routine name */
907 register afs_int32 code = 0; /*Return code */
910 * Make sure we've initialized our VLDB connection(s) before
914 code = InitThisModule(NoAuthFlag, uss_ConfDir, uss_Cell);
921 * Go for the deletion.
925 ("%s: Deleting volume '%s' (ID %d) on FileServer '%s' (0x%x), partition '%s' (%d)\n",
926 rn, a_volName, a_volID, a_servName, a_servID, a_partName,
928 #endif /* USS_VOL_DB */
930 code = UV_DeleteVolume(a_servID, a_partID, a_volID);
932 printf("%s: Can't delete volume '%s'\n", uss_whoami, a_volName);
934 printf("\t[Dry run - volume '%s' NOT removed]\n", a_volName);
938 } /*uss_vol_DeleteVol */
941 /*------------------------------------------------------------------------
942 * static GetServerAndPart
945 * Given a VLDB entry, return the server and partition IDs for
946 * the read/write volume.
949 * a_vldbEntryP : Ptr to VLDB entry.
950 * a_servIDP : Ptr to server ID to set.
951 * a_partIDP : Ptr to partition ID to set.
954 * 0 if everything went well, or
958 * Nothing interesting.
962 *------------------------------------------------------------------------*/
965 GetServerAndPart(struct nvldbentry *a_vldbEntryP, afs_int32 *a_servIDP,
966 afs_int32 *a_partIDP)
967 { /*GetServerAndPart */
970 * It really looks like all we need to do is pull off the
971 * first entry's info.
973 *a_servIDP = a_vldbEntryP->serverNumber[0];
974 *a_partIDP = a_vldbEntryP->serverPartition[0];
977 } /*GetServerAndPart */
980 /*------------------------------------------------------------------------
981 * static ovlentry_to_nvlentry
984 * Converts a vldbentry to nvldbentry.
987 * oentryp IN : Ptr to vldbentry.
988 * nentryp OUT : Ptr to nvldbentry.
994 * Nothing interesting.
998 *------------------------------------------------------------------------*/
1001 ovlentry_to_nvlentry(struct vldbentry *oentryp,
1002 struct nvldbentry *nentryp)
1006 memset(nentryp, 0, sizeof(struct nvldbentry));
1007 strncpy(nentryp->name, oentryp->name, sizeof(nentryp->name));
1008 for (i = 0; i < oentryp->nServers; i++) {
1009 nentryp->serverNumber[i] = oentryp->serverNumber[i];
1010 nentryp->serverPartition[i] = oentryp->serverPartition[i];
1011 nentryp->serverFlags[i] = oentryp->serverFlags[i];
1013 nentryp->nServers = oentryp->nServers;
1014 for (i = 0; i < MAXTYPES; i++)
1015 nentryp->volumeId[i] = oentryp->volumeId[i];
1016 nentryp->cloneId = oentryp->cloneId;
1017 nentryp->flags = oentryp->flags;
1021 /*------------------------------------------------------------------------
1022 * static uss_vol_GetEntryByID
1025 * Obtains a nvldbentry whether new or old forms of
1026 * ubik_VL_GetEntryByID are required.
1029 * cstruct : Ptr to ubik_client.
1030 * volid : Volume ID for which entry is being obtained.
1031 * voltype : Required volume type
1032 * entryp : Ptr to nvldbentry to receive the output on success.
1035 * 0 if everything went well, or
1036 * ubik return code otherwise.
1039 * Nothing interesting.
1043 *------------------------------------------------------------------------*/
1046 uss_vol_GetEntryByID(struct ubik_client *cstruct, afs_uint32 volid,
1047 afs_int32 voltype, struct nvldbentry *entryp)
1049 struct vldbentry oentry;
1052 code = ubik_VL_GetEntryByIDN(cstruct, 0, volid, voltype, entryp);
1053 if (code == RXGEN_OPCODE) {
1055 ubik_VL_GetEntryByID(cstruct, 0, volid, voltype, &oentry);
1057 ovlentry_to_nvlentry(&oentry, entryp);
1063 /*------------------------------------------------------------------------
1064 * EXPORTED uss_vol_GetVolInfoFromMountPoint
1067 * If the mountpoint path provided is not
1071 *------------------------------------------------------------------------*/
1074 uss_vol_GetVolInfoFromMountPoint(char *a_mountpoint)
1075 { /*uss_vol_GetVolInfoFromMountPoint */
1077 static char rn[] = "uss_vol_GetVolInfoFromMountPoint";
1079 register afs_int32 code; /*Return code */
1080 uss_VolumeStatus_t *statusP; /*Ptr to returned status */
1081 afs_int32 volID; /*Volume ID */
1082 struct nvldbentry vldbEntry; /*VLDB entry for volume */
1083 afs_int32 serverID; /*Addr of host FileServer */
1084 afs_int32 partID; /*Volume's partition ID */
1087 * Set up to ask the CacheManager to give us all the info
1088 * it has about the given mountpoint.
1090 code = uss_fs_GetVolStat(a_mountpoint, uss_fs_OutBuff, USS_FS_MAX_SIZE);
1092 printf("[%s] Result of uss_fs_GetVolStat: code = %d, errno = %d\n", rn,
1094 #endif /* USS_VOL_DB */
1096 if (errno == EINVAL || errno == ENOENT || errno == ENODEV) {
1098 * We were given a mountpoint pathname that doesn't
1099 * point to a volume, or a mountpoint that has already
1100 * been deleted. This means that there is no info
1101 * to get from this pathname. Zero out the volume,
1102 * server & partition info and return successfully.
1104 uss_Volume[0] = '\0';
1105 uss_Server[0] = '\0';
1106 uss_Partition[0] = '\0';
1109 uss_PartitionID = 0;
1111 printf("%s: Warning: Mountpoint pathname '%s': ", uss_whoami,
1113 if (errno == EINVAL)
1114 printf("Volume not reachable\n");
1115 else if (errno == ENODEV)
1116 printf("No such device\n");
1118 printf("Not found\n");
1122 printf("%s: Can't get volume information from mountpoint '%s'\n",
1123 uss_whoami, a_mountpoint);
1128 /*Can't get volume status */
1130 * Pull out the volume name from the returned information and store
1131 * it in the common area. It resides right after the basic volume
1134 statusP = (uss_VolumeStatus_t *) uss_fs_OutBuff;
1135 strcpy(uss_Volume, (((char *)statusP) + sizeof(*statusP)));
1136 volID = statusP->Vid;
1137 uss_VolumeID = volID;
1139 printf("%s: Illegal volume ID: %d\n", uss_whoami, volID);
1144 * With the volume name in hand, find out where that volume
1145 * lives. Make sure our VLDB stuff has been initialized first.
1148 code = InitThisModule(NoAuthFlag, uss_ConfDir, uss_Cell);
1152 code = uss_vol_GetEntryByID( uconn_vldbP, volID, -1, &vldbEntry);
1154 printf("%s: Can't fetch VLDB entry for volume ID %d\n", uss_whoami,
1160 * Translate the given VLDB entry from network to host format, then
1161 * checking on the volume's validity. Specifically, it must be a
1162 * read/write volume and must only exist on one server.
1164 MapHostToNetwork(&vldbEntry);
1165 if (vldbEntry.volumeId[RWVOL] != volID) {
1166 printf("%s: Volume '%s' (ID %d) is not a read/write volume!!\n",
1167 uss_whoami, uss_Volume, volID);
1170 if (vldbEntry.nServers != 1) {
1171 printf("%s: Volume '%s' (ID %d) exists on multiple servers!!\n",
1172 uss_whoami, uss_Volume, volID);
1177 * Pull out the int32words containing the server and partition info
1178 * for the read/write volume.
1180 code = GetServerAndPart(&vldbEntry, &serverID, &partID);
1183 ("%s: Can't get server/partition info from VLDB entry for volume '%s' (ID %d)\n",
1184 uss_whoami, uss_Volume, volID);
1189 * Store the raw data, then translate the FileServer address to a
1190 * host name, and the partition ID to a partition name.
1192 uss_ServerID = serverID;
1193 uss_PartitionID = partID;
1194 HostIDToHostName(serverID, uss_Server);
1196 printf("[%s] Server ID 0x%x translated to '%s'\n", rn, serverID,
1198 #endif /* USS_VOL_DB */
1199 code = PartIDToPartName(partID, uss_Partition);
1201 printf("%s: Error translating partition ID %d to partition name\n",
1202 uss_whoami, partID);
1207 * We got it, home boy.
1211 } /*uss_vol_GetVolInfoFromMountPoint */