volser: make splitvol use VolumeId
[openafs.git] / src / volser / volprocs.c
index c2c2843..11b98f7 100644 (file)
@@ -60,6 +60,7 @@
 extern int DoLogging;
 extern struct afsconf_dir *tdir;
 extern int DoPreserveVolumeStats;
+extern int restrictedQueryLevel;
 
 extern void LogError(afs_int32 errcode);
 
@@ -448,9 +449,9 @@ VolPartitionInfo(struct rx_call *acid, char *pname, struct diskPartition64
 {
     struct DiskPartition64 *dp;
 
-/*
-    if (!afsconf_SuperUser(tdir, acid, caller)) return VOLSERBAD_ACCESS;
-*/
+    if (!afsconf_CheckRestrictedQuery(tdir, acid, restrictedQueryLevel))
+        return VOLSERBAD_ACCESS;
+
     VResetDiskUsage();
     dp = VGetPartition(pname, 0);
     if (dp) {
@@ -793,7 +794,8 @@ VolClone(struct rx_call *acid, afs_int32 atrans, VolumeId purgeId,
            VCreateVolume(&error, originalvp->partition->name, newId,
                          V_parentId(originalvp));
        if (error) {
-           Log("1 Volser: Clone: Couldn't create new volume; clone aborted\n");
+           Log("1 Volser: Clone: Couldn't create new volume %" AFS_VOLID_FMT " for parent %" AFS_VOLID_FMT "; clone aborted\n",
+               afs_printable_VolumeId_lu(newId), afs_printable_VolumeId_lu(V_parentId(originalvp)));
            newvp = (Volume *) 0;
            goto fail;
        }
@@ -1126,6 +1128,9 @@ static afs_int32
 VolGetNthVolume(struct rx_call *acid, afs_int32 aindex, afs_uint32 *avolume,
                    afs_int32 *apart)
 {
+    if (!afsconf_CheckRestrictedQuery(tdir, acid, restrictedQueryLevel))
+        return VOLSERBAD_ACCESS;
+
     Log("1 Volser: GetNthVolume: Not yet implemented\n");
     return VOLSERNO_OP;
 }
@@ -1148,6 +1153,9 @@ VolGetFlags(struct rx_call *acid, afs_int32 atid, afs_int32 *aflags)
 {
     struct volser_trans *tt;
 
+    if (!afsconf_CheckRestrictedQuery(tdir, acid, restrictedQueryLevel))
+        return VOLSERBAD_ACCESS;
+
     tt = FindTrans(atid);
     if (!tt)
        return ENOENT;
@@ -1547,6 +1555,11 @@ VolRestore(struct rx_call *acid, afs_int32 atrans, afs_int32 aflags,
        TRELE(tt);
        return ENOENT;
     }
+    if (DoLogging) {
+       char buffer[16];
+       Log("%s on %s is executing Restore %" AFS_VOLID_FMT "\n", caller,
+           callerAddress(acid, buffer), afs_printable_VolumeId_lu(tt->volid));
+    }
     TSetRxCall(tt, acid, "Restore");
 
     DFlushVolume(V_parentId(tt->volume)); /* Ensure dir buffers get dropped */
@@ -1648,6 +1661,8 @@ VolGetStatus(struct rx_call *acid, afs_int32 atrans,
     struct VolumeDiskData *td;
     struct volser_trans *tt;
 
+    if (!afsconf_CheckRestrictedQuery(tdir, acid, restrictedQueryLevel))
+        return VOLSERBAD_ACCESS;
 
     tt = FindTrans(atrans);
     if (!tt)
@@ -1769,6 +1784,9 @@ VolGetName(struct rx_call *acid, afs_int32 atrans, char **aname)
     struct volser_trans *tt;
     int len;
 
+    if (!afsconf_CheckRestrictedQuery(tdir, acid, restrictedQueryLevel))
+        return VOLSERBAD_ACCESS;
+
     /* We need to at least fill it in */
     *aname = malloc(1);
     if (!*aname)
@@ -1833,6 +1851,9 @@ VolListPartitions(struct rx_call *acid, struct pIDs *partIds)
     char namehead[9];
     int i;
 
+    if (!afsconf_CheckRestrictedQuery(tdir, acid, restrictedQueryLevel))
+        return VOLSERBAD_ACCESS;
+
     strcpy(namehead, "/vicep");        /*7 including null terminator */
 
     /* Just return attached partitions. */
@@ -1865,6 +1886,9 @@ XVolListPartitions(struct rx_call *acid, struct partEntries *pEntries)
     struct DiskPartition64 *dp;
     int i, j = 0;
 
+    if (!afsconf_CheckRestrictedQuery(tdir, acid, restrictedQueryLevel))
+        return VOLSERBAD_ACCESS;
+
     strcpy(namehead, "/vicep");        /*7 including null terminator */
 
     /* Only report attached partitions */
@@ -2338,9 +2362,11 @@ VolListOneVolume(struct rx_call *acid, afs_int32 partid,
     DIR *dirp;
     VolumeId volid;
     int found = 0;
-    int code;
     volint_info_handle_t handle;
 
+    if (!afsconf_CheckRestrictedQuery(tdir, acid, restrictedQueryLevel))
+        return VOLSERBAD_ACCESS;
+
     volumeInfo->volEntries_val = calloc(1, sizeof(volintInfo));
     if (!volumeInfo->volEntries_val)
        return ENOMEM;
@@ -2369,19 +2395,20 @@ VolListOneVolume(struct rx_call *acid, afs_int32 partid,
        handle.volinfo_type = VOLINT_INFO_TYPE_BASE;
        handle.volinfo_ptr.base = volumeInfo->volEntries_val;
 
-       code = GetVolInfo(partid,
-                         volid,
-                         pname,
-                         volname,
-                         &handle,
-                         VOL_INFO_LIST_SINGLE);
+       /* The return code from GetVolInfo is ignored; there is no error from
+        * it that results in the whole call being aborted. Any volume
+        * attachment failures are reported in 'status' field in the
+        * volumeInfo payload. */
+       GetVolInfo(partid,
+                  volid,
+                  pname,
+                  volname,
+                  &handle,
+                  VOL_INFO_LIST_SINGLE);
     }
 
     closedir(dirp);
-    if (found)
-        return code ? ENODEV: 0;
-    else
-        return ENODEV;
+    return (found) ? 0 : ENODEV;
 }
 
 /*------------------------------------------------------------------------
@@ -2428,9 +2455,11 @@ VolXListOneVolume(struct rx_call *a_rxCidP, afs_int32 a_partID,
     DIR *dirp;                 /*Partition directory ptr */
     VolumeId currVolID;                /*Current volume ID */
     int found = 0;             /*Did we find the volume we need? */
-    int code;
     volint_info_handle_t handle;
 
+    if (!afsconf_CheckRestrictedQuery(tdir, a_rxCidP, restrictedQueryLevel))
+        return VOLSERBAD_ACCESS;
+
     /*
      * Set up our pointers for action, marking our structure to hold exactly
      * one entry.  Also, assume we'll fail in our quest.
@@ -2440,7 +2469,6 @@ VolXListOneVolume(struct rx_call *a_rxCidP, afs_int32 a_partID,
        return ENOMEM;
 
     a_volumeXInfoP->volXEntries_len = 1;
-    code = ENODEV;
 
     /*
      * If the partition name we've been given is bad, bogue out.
@@ -2484,13 +2512,16 @@ VolXListOneVolume(struct rx_call *a_rxCidP, afs_int32 a_partID,
        handle.volinfo_type = VOLINT_INFO_TYPE_EXT;
        handle.volinfo_ptr.ext = a_volumeXInfoP->volXEntries_val;
 
-       code = GetVolInfo(a_partID,
-                         a_volID,
-                         pname,
-                         volname,
-                         &handle,
-                         VOL_INFO_LIST_SINGLE);
-
+       /* The return code from GetVolInfo is ignored; there is no error from
+        * it that results in the whole call being aborted. Any volume
+        * attachment failures are reported in 'status' field in the
+        * volumeInfo payload. */
+       GetVolInfo(a_partID,
+                  a_volID,
+                  pname,
+                  volname,
+                  &handle,
+                  VOL_INFO_LIST_SINGLE);
     }
 
     /*
@@ -2498,10 +2529,7 @@ VolXListOneVolume(struct rx_call *a_rxCidP, afs_int32 a_partID,
      * return the proper value.
      */
     closedir(dirp);
-    if (found)
-        return code ? ENODEV: 0;
-    else
-        return ENODEV;
+    return (found) ? 0 : ENODEV;
 }                              /*SAFSVolXListOneVolume */
 
 /*returns all the volumes on partition partid. If flags = 1 then all the
@@ -2530,6 +2558,9 @@ VolListVolumes(struct rx_call *acid, afs_int32 partid, afs_int32 flags,
     int code;
     volint_info_handle_t handle;
 
+    if (!afsconf_CheckRestrictedQuery(tdir, acid, restrictedQueryLevel))
+        return VOLSERBAD_ACCESS;
+
     volumeInfo->volEntries_val = calloc(allocSize, sizeof(volintInfo));
     if (!volumeInfo->volEntries_val)
        return ENOMEM;
@@ -2640,6 +2671,9 @@ VolXListVolumes(struct rx_call *a_rxCidP, afs_int32 a_partID,
     int code;
     volint_info_handle_t handle;
 
+    if (!afsconf_CheckRestrictedQuery(tdir, a_rxCidP, restrictedQueryLevel))
+        return VOLSERBAD_ACCESS;
+
     /*
      * Allocate a large array of extended volume info structures, then
      * set it up for action.
@@ -2756,6 +2790,9 @@ VolMonitor(struct rx_call *acid, transDebugEntries *transInfo)
     afs_int32 allocSize = 50;
     struct volser_trans *tt, *nt, *allTrans;
 
+    if (!afsconf_CheckRestrictedQuery(tdir, acid, restrictedQueryLevel))
+        return VOLSERBAD_ACCESS;
+
     transInfo->transDebugEntries_val =
        malloc(allocSize * sizeof(transDebugInfo));
     if (!transInfo->transDebugEntries_val)
@@ -3006,7 +3043,7 @@ SAFSVolGetSize(struct rx_call *acid, afs_int32 fromTrans, afs_int32 fromDate,
 }
 
 afs_int32
-SAFSVolSplitVolume(struct rx_call *acall, afs_uint32 vid, afs_uint32 new,
+SAFSVolSplitVolume(struct rx_call *acall, afs_uint32 ovid, afs_uint32 onew,
                   afs_uint32 where, afs_int32 verbose)
 {
 #if defined(AFS_NAMEI_ENV) && !defined(AFS_NT40_ENV)
@@ -3015,6 +3052,8 @@ SAFSVolSplitVolume(struct rx_call *acall, afs_uint32 vid, afs_uint32 new,
     struct volser_trans *tt = 0, *tt2 = 0;
     char caller[MAXKTCNAMELEN];
     char line[128];
+    VolumeId new = onew;
+    VolumeId vid = ovid;
 
     if (!afsconf_SuperUser(tdir, acall, caller))
         return EPERM;
@@ -3035,12 +3074,14 @@ SAFSVolSplitVolume(struct rx_call *acall, afs_uint32 vid, afs_uint32 new,
     if (V_device(vol) != V_device(newvol)
        || V_uniquifier(newvol) != 2) {
         if (V_device(vol) != V_device(newvol)) {
-            sprintf(line, "Volumes %u and %u are not in the same partition, aborted.\n",
-                   vid, new);
+            sprintf(line, "Volumes %" AFS_VOLID_FMT " and %" AFS_VOLID_FMT " are not in the same partition, aborted.\n",
+                   afs_printable_VolumeId_lu(vid),
+                   afs_printable_VolumeId_lu(new));
             rx_Write(acall, line, strlen(line));
         }
         if (V_uniquifier(newvol) != 2) {
-            sprintf(line, "Volume %u is not freshly created, aborted.\n", new);
+            sprintf(line, "Volume %" AFS_VOLID_FMT " is not freshly created, aborted.\n",
+                   afs_printable_VolumeId_lu(new));
             rx_Write(acall, line, strlen(line));
         }
         line[0] = 0;
@@ -3051,7 +3092,8 @@ SAFSVolSplitVolume(struct rx_call *acall, afs_uint32 vid, afs_uint32 new,
     }
     tt = NewTrans(vid, V_device(vol));
     if (!tt) {
-        sprintf(line, "Couldn't create transaction for %u, aborted.\n", vid);
+        sprintf(line, "Couldn't create transaction for %" AFS_VOLID_FMT ", aborted.\n",
+               afs_printable_VolumeId_lu(vid));
         rx_Write(acall, line, strlen(line));
         line[0] = 0;
         rx_Write(acall, line, 1);
@@ -3067,7 +3109,8 @@ SAFSVolSplitVolume(struct rx_call *acall, afs_uint32 vid, afs_uint32 new,
 
     tt2 = NewTrans(new, V_device(newvol));
     if (!tt2) {
-        sprintf(line, "Couldn't create transaction for %u, aborted.\n", new);
+        sprintf(line, "Couldn't create transaction for %" AFS_VOLID_FMT ", aborted.\n",
+               afs_printable_VolumeId_lu(new));
         rx_Write(acall, line, strlen(line));
         line[0] = 0;
         rx_Write(acall, line, 1);