libadmin: Remove redundant memset call
[openafs.git] / src / libadmin / vos / afs_vosAdmin.c
index e3fbbc5..dfcef7f 100644 (file)
@@ -9,45 +9,38 @@
 
 #include <afsconfig.h>
 #include <afs/param.h>
+#include <afs/stds.h>
 
-RCSID
-    ("$Header$");
+#include <roken.h>
 
-#include <afs/stds.h>
-#include <stdio.h>
-#ifdef HAVE_STRING_H
-#include <string.h>
-#else
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif
-#endif
 #include <ctype.h>
-#ifdef AFS_NT40_ENV
-#include <winsock2.h>
-#include <io.h>
-#else
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <unistd.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-#endif
-#include "afs_vosAdmin.h"
-#include "../adminutil/afs_AdminInternal.h"
-#include <afs/afs_utilAdmin.h>
+
 #include <afs/vlserver.h>
+#include <afs/afsint.h>
 #include <afs/volser.h>
 #include <afs/volint.h>
+
+#include "afs_vosAdmin.h"
+#include "../adminutil/afs_AdminInternal.h"
+
+/* File descriptors are HANDLE's on NT. The following typedef helps catch
+ * type errors. Duplicated from vol/ihandle.h
+ */
+#ifdef AFS_NT40_ENV
+typedef HANDLE FD_t;
+#else
+typedef int FD_t;
+#endif
+#define INVALID_FD ((FD_t)-1)
+
 #include <afs/partition.h>
 #include <rx/rx.h>
+#include <rx/rxstat.h>
+#include <afs/afs_utilAdmin.h>
 #include "vosutils.h"
 #include "vsprocs.h"
 #include "lockprocs.h"
 
-extern int VL_GetAddrsU();
-
 typedef struct file_server {
     int begin_magic;
     int is_valid;
@@ -325,14 +318,15 @@ vos_BackupVolumeCreateMultiple(const void *cellHandle,
     size_t prefix_len = 0;
     nbulkentries arrayEntries;
     afs_int32 nentries = 0;
-    register struct nvldbentry *entry;
+    struct nvldbentry *entry;
     int i;
     afs_int32 rw_volid, rw_server, rw_partition;
     int previdx;
     int equal = 0;
     char backbuf[1024];
 
-    memset((void *)&attr, 0, sizeof(attr));
+    memset(&attr, 0, sizeof(attr));
+    memset(&arrayEntries, 0, sizeof(arrayEntries));
 
     /*
      * Validate arguments
@@ -378,8 +372,6 @@ vos_BackupVolumeCreateMultiple(const void *cellHandle,
        prefix_len = strlen(volumePrefix);
     }
 
-    memset((void *)&arrayEntries, 0, sizeof(arrayEntries));
-
     /*
      * Get a list of all the volumes in the cell
      */
@@ -569,8 +561,10 @@ vos_PartitionGet(const void *cellHandle, const void *serverHandle,
     if (tst) {
        goto fail_vos_PartitionGet;
     }
-    strcpy(partitionP->name, part_info.name);
-    strcpy(partitionP->deviceName, part_info.devName);
+    strncpy(partitionP->name, part_info.name, VOS_MAX_PARTITION_NAME_LEN);
+    partitionP->name[VOS_MAX_PARTITION_NAME_LEN-1] = '\0';
+    strncpy(partitionP->deviceName, part_info.devName, VOS_MAX_PARTITION_NAME_LEN);
+    partitionP->deviceName[VOS_MAX_PARTITION_NAME_LEN-1] = '\0';
     partitionP->lockFileDescriptor = part_info.lock_fd;
     partitionP->totalSpace = part_info.minFree;
     partitionP->totalFreeSpace = part_info.free;
@@ -693,10 +687,8 @@ vos_PartitionGetBegin(const void *cellHandle, const void *serverHandle,
     int rc = 0;
     afs_status_t tst = 0;
     file_server_p f_server = (file_server_p) serverHandle;
-    afs_admin_iterator_p iter =
-       (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
-    partition_get_p part =
-       (partition_get_p) calloc(1, sizeof(partition_get_t));
+    afs_admin_iterator_p iter = malloc(sizeof(afs_admin_iterator_t));
+    partition_get_p part = calloc(1, sizeof(partition_get_t));
 
     /*
      * Validate arguments
@@ -882,7 +874,7 @@ vos_ServerOpen(const void *cellHandle, const char *serverName,
     int rc = 0;
     afs_status_t tst = 0;
     afs_cell_handle_p c_handle = (afs_cell_handle_p) cellHandle;
-    file_server_p f_server = (file_server_p) malloc(sizeof(file_server_t));
+    file_server_p f_server = malloc(sizeof(file_server_t));
     int server_address;
     struct rx_securityClass *sc[3];
     int scIndex;
@@ -1075,8 +1067,9 @@ vos_ServerSync(const void *cellHandle, const void *serverHandle,
 
 int ADMINAPI
 vos_FileServerAddressChange(const void *cellHandle,
-                           vos_MessageCallBack_t callBack, int oldAddress,
-                           int newAddress, afs_status_p st)
+                           vos_MessageCallBack_t callBack,
+                           unsigned int oldAddress,
+                           unsigned int newAddress, afs_status_p st)
 {
     int rc = 0;
     afs_status_t tst = 0;
@@ -1091,8 +1084,7 @@ vos_FileServerAddressChange(const void *cellHandle,
     }
 
     tst =
-       ubik_Call_New(VL_ChangeAddr, c_handle->vos, 0, oldAddress,
-                     newAddress);
+       ubik_VL_ChangeAddr(c_handle->vos, 0, oldAddress, newAddress);
     if (tst) {
        goto fail_vos_FileServerAddressChange;
     }
@@ -1130,13 +1122,14 @@ vos_FileServerAddressChange(const void *cellHandle,
 
 int ADMINAPI
 vos_FileServerAddressRemove(const void *cellHandle,
-                           vos_MessageCallBack_t callBack, int serverAddress,
+                           vos_MessageCallBack_t callBack,
+                           unsigned int serverAddress,
                            afs_status_p st)
 {
     int rc = 0;
     afs_status_t tst = 0;
     afs_cell_handle_p c_handle = (afs_cell_handle_p) cellHandle;
-    int dummyAddress = 0xffffffff;
+    unsigned int dummyAddress = 0xffffffff;
 
     /*
      * Validate arguments
@@ -1147,7 +1140,7 @@ vos_FileServerAddressRemove(const void *cellHandle,
     }
 
     tst =
-       ubik_Call_New(VL_ChangeAddr, c_handle->vos, 0, dummyAddress,
+       ubik_VL_ChangeAddr(c_handle->vos, 0, dummyAddress,
                      serverAddress);
     if (tst) {
        goto fail_vos_FileServerAddressRemove;
@@ -1217,7 +1210,7 @@ GetServerRPC(void *rpc_specific, int slot, int *last_item,
            addr_multi.bulkaddrs_val = 0;
            addr_multi.bulkaddrs_len = 0;
            tst =
-               ubik_Call(VL_GetAddrsU, serv->vldb, 0, &m_attrs, &m_uuid,
+               ubik_VL_GetAddrsU(serv->vldb, 0, &m_attrs, &m_uuid,
                          &m_unique, &total_multi, &addr_multi);
            if (tst) {
                goto fail_GetServerRPC;
@@ -1339,9 +1332,8 @@ vos_FileServerGetBegin(const void *cellHandle, vos_MessageCallBack_t callBack,
     int rc = 0;
     afs_status_t tst = 0;
     afs_cell_handle_p c_handle = (afs_cell_handle_p) cellHandle;
-    afs_admin_iterator_p iter =
-       (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
-    server_get_p serv = (server_get_p) calloc(1, sizeof(server_get_t));
+    afs_admin_iterator_p iter = malloc(sizeof(afs_admin_iterator_t));
+    server_get_p serv = calloc(1, sizeof(server_get_t));
     struct VLCallBack unused;
 
 
@@ -1368,7 +1360,7 @@ vos_FileServerGetBegin(const void *cellHandle, vos_MessageCallBack_t callBack,
 
     serv->vldb = c_handle->vos;
     tst =
-       ubik_Call_New(VL_GetAddrs, c_handle->vos, 0, 0, 0, &unused,
+       ubik_VL_GetAddrs(c_handle->vos, 0, 0, 0, &unused,
                      &serv->total_addresses, &serv->addresses);
 
     if (tst) {
@@ -1678,10 +1670,8 @@ vos_ServerTransactionStatusGetBegin(const void *cellHandle,
     int rc = 0;
     afs_status_t tst = 0;
     file_server_p f_server = (file_server_p) serverHandle;
-    afs_admin_iterator_p iter =
-       (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
-    transaction_get_p tran =
-       (transaction_get_p) calloc(1, sizeof(transaction_get_t));
+    afs_admin_iterator_p iter = malloc(sizeof(afs_admin_iterator_t));
+    transaction_get_p tran = calloc(1, sizeof(transaction_get_t));
 
 
     /*
@@ -1882,7 +1872,8 @@ copyVLDBEntry(struct nvldbentry *source, vos_vldbEntry_p dest,
        dest->status |= VOS_VLDB_ENTRY_BACKEXISTS;
     }
 
-    strcpy(dest->name, source->name);
+    strncpy(dest->name, source->name, VOS_MAX_VOLUME_NAME_LEN);
+    dest->name[VOS_MAX_VOLUME_NAME_LEN - 1] = '\0';
     for (i = 0; i < VOS_MAX_REPLICA_SITES; i++) {
        dest->volumeSites[i].serverAddress = source->serverNumber[i];
        dest->volumeSites[i].serverPartition = source->serverPartition[i];
@@ -1942,7 +1933,7 @@ copyVLDBEntry(struct nvldbentry *source, vos_vldbEntry_p dest,
 
 int ADMINAPI
 vos_VLDBGet(const void *cellHandle, vos_MessageCallBack_t callBack,
-           const unsigned int *volumeId, const char *volumeName,
+           const unsigned int *volumeId, char *volumeName,
            vos_vldbEntry_p vldbEntry, afs_status_p st)
 {
     int rc = 0;
@@ -1977,11 +1968,11 @@ vos_VLDBGet(const void *cellHandle, vos_MessageCallBack_t callBack,
        if (!ValidateVolumeName(volumeName, &tst)) {
            goto fail_vos_VLDBGet;
        }
-       if (!VLDB_GetEntryByName(c_handle, volumeName, &entry, &tst)) {
+       if (!aVLDB_GetEntryByName(c_handle, volumeName, &entry, &tst)) {
            goto fail_vos_VLDBGet;
        }
     } else {
-       if (!VLDB_GetEntryByID(c_handle, *volumeId, -1, &entry, &tst)) {
+       if (!aVLDB_GetEntryByID(c_handle, *volumeId, -1, &entry, &tst)) {
            goto fail_vos_VLDBGet;
        }
     }
@@ -2127,10 +2118,8 @@ vos_VLDBGetBegin(const void *cellHandle, const void *serverHandle,
     afs_status_t tst = 0;
     afs_cell_handle_p c_handle = (afs_cell_handle_p) cellHandle;
     file_server_p f_server = (file_server_p) serverHandle;
-    afs_admin_iterator_p iter =
-       (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
-    vldb_entry_get_p entry =
-       (vldb_entry_get_p) calloc(1, sizeof(vldb_entry_get_t));
+    afs_admin_iterator_p iter = malloc(sizeof(afs_admin_iterator_t));
+    vldb_entry_get_p entry = calloc(1, sizeof(vldb_entry_get_t));
     struct VldbListByAttributes attr;
 
     attr.Mask = 0;
@@ -2356,7 +2345,7 @@ vos_VLDBEntryRemove(const void *cellHandle, const void *serverHandle,
      */
 
     if (volumeId != NULL) {
-       tst = ubik_Call(VL_DeleteEntry, c_handle->vos, 0, *volumeId, -1);
+       tst = ubik_VL_DeleteEntry(c_handle->vos, 0, *volumeId, -1);
        if (tst != 0) {
            goto fail_vos_VLDBEntryRemove;
        }
@@ -2394,8 +2383,8 @@ vos_VLDBEntryRemove(const void *cellHandle, const void *serverHandle,
     }
 
     for (i = 0; i < nentries; i++) {
-       ubik_Call(VL_DeleteEntry, c_handle->vos, 0,
-                 entries.nbulkentries_val[i].volumeId[RWVOL]);
+       ubik_VL_DeleteEntry(c_handle->vos, 0,
+                 entries.nbulkentries_val[i].volumeId[RWVOL], -1);
     }
     rc = 1;
 
@@ -2548,7 +2537,7 @@ vos_VLDBEntryLock(const void *cellHandle, vos_MessageCallBack_t callBack,
        goto fail_vos_VLDBEntryLock;
     }
 
-    tst = ubik_Call(VL_SetLock, c_handle->vos, 0, volumeId, -1, VLOP_DELETE);
+    tst = ubik_VL_SetLock(c_handle->vos, 0, volumeId, -1, VLOP_DELETE);
     if (tst != 0) {
        goto fail_vos_VLDBEntryLock;
     }
@@ -2602,7 +2591,7 @@ vos_VLDBEntryUnlock(const void *cellHandle, vos_MessageCallBack_t callBack,
 
 
     tst =
-       ubik_Call(VL_ReleaseLock, c_handle->vos, 0, volumeId, -1,
+       ubik_VL_ReleaseLock(c_handle->vos, 0, volumeId, -1,
                  LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP);
     if (tst != 0) {
        goto fail_vos_VLDBEntryUnlock;
@@ -2872,7 +2861,7 @@ vos_VLDBSync(const void *cellHandle, const void *serverHandle,
 int ADMINAPI
 vos_VolumeCreate(const void *cellHandle, const void *serverHandle,
                 vos_MessageCallBack_t callBack, unsigned int partition,
-                const char *volumeName, unsigned int quota,
+                char *volumeName, unsigned int quota,
                 unsigned int *volumeId, afs_status_p st)
 {
     int rc = 0;
@@ -2921,7 +2910,7 @@ vos_VolumeCreate(const void *cellHandle, const void *serverHandle,
      * Check that the volume doesn't already exist
      */
 
-    if (VLDB_GetEntryByName(c_handle, volumeName, &vinfo, &tst)) {
+    if (aVLDB_GetEntryByName(c_handle, volumeName, &vinfo, &tst)) {
        tst = ADMVOSVOLUMENAMEDUP;
        goto fail_vos_VolumeCreate;
     }
@@ -3044,7 +3033,7 @@ vos_VolumeDelete(const void *cellHandle, const void *serverHandle,
 
 int ADMINAPI
 vos_VolumeRename(const void *cellHandle, vos_MessageCallBack_t callBack,
-                unsigned int readWriteVolumeId, const char *newVolumeName,
+                unsigned int readWriteVolumeId, char *newVolumeName,
                 afs_status_p st)
 {
     int rc = 0;
@@ -3069,7 +3058,7 @@ vos_VolumeRename(const void *cellHandle, vos_MessageCallBack_t callBack,
      * Retrieve the entry
      */
 
-    if (!VLDB_GetEntryByID(c_handle, readWriteVolumeId, -1, &entry, &tst)) {
+    if (!aVLDB_GetEntryByID(c_handle, readWriteVolumeId, -1, &entry, &tst)) {
        goto fail_vos_VolumeRename;
     }
 
@@ -3214,7 +3203,7 @@ vos_VolumeDump(const void *cellHandle, const void *serverHandle,
 int ADMINAPI
 vos_VolumeRestore(const void *cellHandle, const void *serverHandle,
                  vos_MessageCallBack_t callBack, unsigned int partition,
-                 unsigned int *volumeId, const char *volumeName,
+                 unsigned int *volumeId, char *volumeName,
                  const char *dumpFile, vos_volumeRestoreType_t dumpType,
                  afs_status_p st)
 {
@@ -3263,7 +3252,7 @@ vos_VolumeRestore(const void *cellHandle, const void *serverHandle,
      */
 
     if (volumeId != NULL) {
-       if (!VLDB_GetEntryByID(c_handle, *volumeId, -1, &entry, &tst)) {
+       if (!aVLDB_GetEntryByID(c_handle, *volumeId, -1, &entry, &tst)) {
            goto fail_vos_VolumeRestore;
        }
        volid = *volumeId;
@@ -3291,7 +3280,7 @@ vos_VolumeRestore(const void *cellHandle, const void *serverHandle,
        close(fd);
     }
 
-    if (!VLDB_GetEntryByName(c_handle, volumeName, &entry, &tst)) {
+    if (!aVLDB_GetEntryByName(c_handle, volumeName, &entry, &tst)) {
        restoreflags = RV_FULLRST;
     } else if (Lp_GetRwIndex(c_handle, &entry, 0) == -1) {
        restoreflags = RV_FULLRST;
@@ -3500,7 +3489,7 @@ copyvolintXInfo(struct volintXInfo *source, vos_volumeEntry_p dest,
      * user from seeing stale data from a previous call
      */
 
-    memset(dest, 0, sizeof(dest));
+    memset(dest, 0, sizeof(*dest));
 
     switch (source->status) {
     case VOK:
@@ -3547,7 +3536,8 @@ copyvolintXInfo(struct volintXInfo *source, vos_volumeEntry_p dest,
      */
 
     if (dest->status == VOS_OK) {
-       strcpy(dest->name, source->name);
+       strncpy(dest->name, source->name, VOS_MAX_VOLUME_NAME_LEN);
+        dest->name[VOS_MAX_VOLUME_NAME_LEN - 1] = '\0';
        dest->id = source->volid;
        if (source->type == 0) {
            dest->type = VOS_READ_WRITE_VOLUME;
@@ -3807,9 +3797,8 @@ vos_VolumeGetBegin(const void *cellHandle, const void *serverHandle,
     int rc = 0;
     afs_status_t tst = 0;
     file_server_p f_server = (file_server_p) serverHandle;
-    afs_admin_iterator_p iter =
-       (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
-    volume_get_p entry = (volume_get_p) calloc(1, sizeof(volume_get_t));
+    afs_admin_iterator_p iter = malloc(sizeof(afs_admin_iterator_t));
+    volume_get_p entry = calloc(1, sizeof(volume_get_t));
 
     /*
      * Validate arguments
@@ -4406,8 +4395,10 @@ vos_VolumeQuotaChange(const void *cellHandle, const void *serverHandle,
 
     memset((void *)&tstatus, 0, sizeof(tstatus));
     tstatus.dayUse = -1;
+    tstatus.spare2 = -1;
     tstatus.maxquota = volumeQuota;
 
+
     tst =
        AFSVolTransCreate(f_server->serv, volumeId, partition, ITBusy, &ttid);
     if (tst) {
@@ -4445,3 +4436,187 @@ vos_VolumeQuotaChange(const void *cellHandle, const void *serverHandle,
     }
     return rc;
 }
+/*
+ * vos_VolumeGet2 - get information about a particular volume.
+ *
+ * PARAMETERS
+ *
+ * IN cellHandle - a previously opened cellHandle that corresponds
+ * to the cell where the volume exists.
+ *
+ * IN serverHandle - a previously opened serverHandle that corresponds
+ * to the server where the volume exists.
+ *
+ * IN callBack - a call back function pointer that may be called to report
+ * status information.  Can be null.
+ *
+ * IN partition - the partition where the volume exists.
+ *
+ * IN volumeId - the volume id of the volume to be retrieved.
+ *
+ * OUT pinfo - upon successful completion, contains the information about the 
+ * specified volume.
+ *
+ * LOCKS
+ * 
+ * No locks are obtained or released by this function
+ *
+ * RETURN CODES
+ *
+ * Returns != 0 upon successful completion.
+ */
+
+int ADMINAPI
+vos_VolumeGet2(const void *cellHandle, const void *serverHandle,
+             vos_MessageCallBack_t callBack, unsigned int partition,
+             unsigned int volumeId, volintInfo* pinfo,
+             afs_status_p st)
+{
+    int rc = 0;
+    afs_status_t tst = 0;
+    file_server_p f_server = (file_server_p) serverHandle;
+    volintInfo *pinfo_=0;
+
+    /*
+     * Validate arguments
+     */
+
+    if (!IsValidServerHandle(f_server, &tst)) {
+       goto fail_vos_VolumeGet2;
+    }
+
+    if (partition > VOLMAXPARTS) {
+       tst = ADMVOSPARTITIONIDTOOLARGE;
+       goto fail_vos_VolumeGet2;
+    }
+
+    if (pinfo == NULL) {
+       tst = ADMVOSVOLUMEPNULL;
+       goto fail_vos_VolumeGet2;
+    }
+
+    /*
+     * Retrieve the information for the volume
+     */
+
+    if (!UV_ListOneVolume(f_server->serv, partition, volumeId, &pinfo_,&tst)) {
+       goto fail_vos_VolumeGet2;
+    }
+
+
+    rc = 1;
+
+  fail_vos_VolumeGet2:
+
+    if (pinfo_ != NULL) {
+     memcpy(pinfo,pinfo_,sizeof(volintInfo));
+       free(pinfo_);
+    }
+
+    if (st != NULL) {
+       *st = tst;
+    }
+    return rc;
+}
+
+/*
+ * vos_ClearVolUpdateCounter - reset volUpdateCounter of a volume to zero
+ *
+ * PARAMETERS
+ *
+ * IN cellHandle - a previously opened cellHandle that corresponds
+ * to the cell where the volume exists.
+ *
+ * IN serverHandle - a previously opened serverHandle that corresponds
+ * to the server where the volume exists.
+ *
+ * IN partition - the partition where the volume exists.
+ *
+ * IN volumeId - the volume id of the volume to be retrieved.
+ *
+ * LOCKS
+ * 
+ * No locks are obtained or released by this function
+ *
+ * RETURN CODES
+ *
+ * Returns != 0 upon successful completion.
+ */
+
+int ADMINAPI
+vos_ClearVolUpdateCounter(const void *cellHandle,
+                                 const void *serverHandle,
+                                 unsigned int partition,
+                                 unsigned int volumeId,
+                                 afs_status_p st)
+{
+    int rc = 0;
+    afs_status_t tst = 0;
+    afs_cell_handle_p c_handle = (afs_cell_handle_p) cellHandle;
+    file_server_p f_server = (file_server_p) serverHandle;
+    int ttid = 0;
+    int rcode = 0;
+    struct volintInfo tstatus;
+    int active_trans = 0;
+
+    /*
+     * Verify that the cellHandle is capable of making vos rpc's
+     */
+
+    if (!IsValidCellHandle(c_handle, &tst)) {
+       goto fail_vos_ClearVolUpdateCounter;
+    }
+
+    if (!IsValidServerHandle(f_server, &tst)) {
+       goto fail_vos_ClearVolUpdateCounter;
+    }
+
+    memset((void *)&tstatus, 0, sizeof(tstatus));
+    tstatus.maxquota = -1;
+    tstatus.dayUse = -1;
+    tstatus.creationDate = -1;
+    tstatus.updateDate = -1;
+    tstatus.flags = -1;
+    tstatus.spare0 = -1;
+    tstatus.spare1 = -1;
+    tstatus.spare2 = 0;
+    tstatus.spare3 = -1;
+    
+    tst =
+       AFSVolTransCreate(f_server->serv, volumeId, partition, ITBusy, &ttid);
+    if (tst) {
+       goto fail_vos_ClearVolUpdateCounter;
+    }
+    active_trans = 1;
+
+    tst = AFSVolSetInfo(f_server->serv, ttid, &tstatus);
+    if (tst) {
+       goto fail_vos_ClearVolUpdateCounter;
+    }
+    rc = 1;
+
+  fail_vos_ClearVolUpdateCounter:
+
+    if (active_trans) {
+       afs_status_t tst2 = 0;
+       tst2 = AFSVolEndTrans(f_server->serv, ttid, &rcode);
+       if (tst2) {
+           if (tst == 0) {
+               tst = tst2;
+               rc = 0;
+           }
+       }
+       if (rcode) {
+           if (tst == 0) {
+               tst = rcode;
+               rc = 0;
+           }
+       }
+    }
+
+    if (st != NULL) {
+       *st = tst;
+    }
+    return rc;
+}
+