#include <roken.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <string.h>
-#include <errno.h>
-#ifdef AFS_NT40_ENV
-#include <stdlib.h>
-#include <fcntl.h>
-#include <winsock2.h>
-#else
-#include <sys/file.h>
-#include <netinet/in.h>
-#include <unistd.h>
-#endif
-
-#include <dirent.h>
-#include <sys/stat.h>
#include <rx/xdr.h>
#include <rx/rx.h>
#include <rx/rxkad.h>
#include <afs/afsint.h>
-#include <signal.h>
-#include <afs/afs_assert.h>
#include <afs/prs_fs.h>
#include <afs/nfs.h>
#include <lwp.h>
#include "afs/audit.h"
#include <afs/dir.h>
#include <afs/afsutil.h>
+#include <afs/com_err.h>
#include <afs/vol_prototypes.h>
#include <afs/errors.h>
afs_uint32);
static afs_int32 VolSetDate(struct rx_call *, afs_int32, afs_int32);
+/**
+ * Return the host address of the caller as a string.
+ *
+ * @param[in] acid incoming rx call
+ * @param[out] buffer buffer to be filled with the addess string
+ *
+ * @return address as formatted by inet_ntoa
+ */
+static_inline char *
+callerAddress(struct rx_call *acid, char *buffer)
+{
+ afs_uint32 ip = rx_HostOf(rx_PeerOf(rx_ConnectionOf(acid)));
+ return afs_inet_ntoa_r(ip, buffer);
+}
+
/* this call unlocks all of the partition locks we've set */
int
VPFullUnlock_r(void)
}
/* Adapted from the file server; create a root directory for this volume */
-static int
+static Error
ViceCreateRoot(Volume *vp)
{
DirHandle dir;
struct acl_accessList *ACL;
AFSFid did;
- Inode inodeNumber, nearInode;
+ Inode inodeNumber, AFS_UNUSED nearInode;
struct VnodeDiskObject *vnode;
struct VnodeClassInfo *vcp = &VnodeClassInfo[vLarge];
IHandle_t *h;
IH_CREATE(V_linkHandle(vp), V_device(vp),
VPartitionPath(V_partition(vp)), nearInode, V_parentId(vp),
1, 1, 0);
- osi_Assert(VALID_INO(inodeNumber));
+ if (!VALID_INO(inodeNumber)) {
+ Log("ViceCreateRoot: IH_CREATE: %s\n", afs_error_message(errno));
+ free(vnode);
+ return EIO;
+ }
SetSalvageDirHandle(&dir, V_parentId(vp), vp->device, inodeNumber);
did.Volume = V_id(vp);
did.Vnode = (VnodeId) 1;
did.Unique = 1;
- osi_Assert(!(MakeDir(&dir, (afs_int32 *)&did, (afs_int32 *)&did)));
+ osi_Assert(!(afs_dir_MakeDir(&dir, (afs_int32 *)&did, (afs_int32 *)&did)));
DFlush(); /* flush all modified dir buffers out */
- DZap((afs_int32 *)&dir); /* Remove all buffers for this dir */
- length = Length(&dir); /* Remember size of this directory */
+ DZap(&dir); /* Remove all buffers for this dir */
+ length = afs_dir_Length(&dir); /* Remember size of this directory */
FidZap(&dir); /* Done with the dir handle obtained via SetSalvageDirHandle() */
V_diskused(vp) = nBlocks(length);
free(vnode);
- return 1;
+ return 0;
}
afs_int32
/* check for access */
if (!afsconf_SuperUser(tdir, acid, caller))
return VOLSERBAD_ACCESS;
- if (DoLogging)
- Log("%s is executing VolNukeVolume %u\n", caller, avolID);
+ if (DoLogging) {
+ char buffer[16];
+ Log("%s on %s is executing VolNukeVolume %u\n", caller,
+ callerAddress(acid, buffer), avolID);
+ }
if (volutil_PartitionName2_r(apartID, partName, sizeof(partName)) != 0)
return VOLSERNOVOL;
return VOLSERBADNAME;
if (!afsconf_SuperUser(tdir, acid, caller))
return VOLSERBAD_ACCESS;
- if (DoLogging)
- Log("%s is executing CreateVolume '%s'\n", caller, aname);
+ if (DoLogging) {
+ char buffer[16];
+ Log("%s on %s is executing CreateVolume '%s'\n", caller,
+ callerAddress(acid, buffer), aname);
+ }
if ((error = ConvertPartition(apart, ppath, sizeof(ppath))))
return error; /*a standard unix error */
if (atype != readwriteVolume && atype != readonlyVolume
V_inService(vp) = V_blessed(vp) = 1;
V_type(vp) = atype;
AssignVolumeName(&V_disk(vp), aname, 0);
- if (doCreateRoot)
- ViceCreateRoot(vp);
+ if (doCreateRoot) {
+ error = ViceCreateRoot(vp);
+ if (error) {
+ Log("1 Volser: CreateVolume: Unable to create volume root dir; "
+ "error code %u\n", (unsigned)error);
+ DeleteTrans(tt, 1);
+ V_needsSalvaged(vp) = 1;
+ VDetachVolume(&junk, vp);
+ return EIO;
+ }
+ }
V_destroyMe(vp) = DESTROY_ME;
V_inService(vp) = 0;
V_maxquota(vp) = 5000; /* set a quota of 5000 at init time */
TRELE(tt);
return ENOENT;
}
- if (DoLogging)
- Log("%s is executing Delete Volume %u\n", caller, tt->volid);
+ if (DoLogging) {
+ char buffer[16];
+ Log("%s on %s is executing Delete Volume %u\n", caller,
+ callerAddress(acid, buffer), tt->volid);
+ }
TSetRxCall(tt, acid, "DeleteVolume");
VPurgeVolume(&error, tt->volume); /* don't check error code, it is not set! */
V_destroyMe(tt->volume) = DESTROY_ME;
return VOLSERBADNAME;
if (!afsconf_SuperUser(tdir, acid, caller))
return VOLSERBAD_ACCESS; /*not a super user */
- if (DoLogging)
- Log("%s is executing Clone Volume new name=%s\n", caller, newName);
+ if (DoLogging) {
+ char buffer[16];
+ Log("%s on %s is executing Clone Volume new name=%s\n", caller,
+ callerAddress(acid, buffer), newName);
+ }
error = 0;
originalvp = (Volume *) 0;
purgevp = (Volume *) 0;
DeleteTrans(ttc, 1);
#ifdef AFS_DEMAND_ATTACH_FS
if (salv_vp && error != VVOLEXISTS && error != EXDEV) {
- Error salv_error;
- VRequestSalvage_r(&salv_error, salv_vp, FSYNC_SALVAGE, 0);
+ V_needsSalvaged(salv_vp) = 1;
}
#endif /* AFS_DEMAND_ATTACH_FS */
return error;
/*not a super user */
if (!afsconf_SuperUser(tdir, acid, caller))
return VOLSERBAD_ACCESS;
- if (DoLogging)
- Log("%s is executing Reclone Volume %u\n", caller, cloneId);
+ if (DoLogging) {
+ char buffer[16];
+ Log("%s on %s is executing Reclone Volume %u\n", caller,
+ callerAddress(acid, buffer), cloneId);
+ }
error = 0;
clonevp = originalvp = (Volume *) 0;
tt = (struct volser_trans *)0;
}
-/*extract the volume id from string vname. Its of the form " V0*<id>.vol "*/
-afs_int32
-ExtractVolId(char vname[])
-{
- int i;
- char name[VOLSER_MAXVOLNAME + 1];
-
- strcpy(name, vname);
- i = 0;
- while (name[i] == 'V' || name[i] == '0')
- i++;
-
- name[11] = '\0'; /* smash the "." */
- return (atol(&name[i]));
-}
-
/*return the name of the next volume header in the directory associated with dirp and dp.
*the volume id is returned in volid, and volume header name is returned in volname*/
int
dp = readdir(dirp); /*read next entry in the directory */
if (dp) {
if ((dp->d_name[0] == 'V') && !strcmp(&(dp->d_name[11]), VHDREXT)) {
- *volid = ExtractVolId(dp->d_name);
+ *volid = VolumeNumber(dp->d_name);
strcpy(volname, dp->d_name);
return 0; /*return the name of the file representing a volume */
} else {
}
closedir(dirp);
- return (found) ? 0 : ENODEV;
+ if (found)
+ return code ? ENODEV: 0;
+ else
+ return ENODEV;
}
/*------------------------------------------------------------------------
* return the proper value.
*/
closedir(dirp);
- return (found) ? 0 : ENODEV;
+ if (found)
+ return code ? ENODEV: 0;
+ else
+ return ENODEV;
} /*SAFSVolXListOneVolume */
/*returns all the volumes on partition partid. If flags = 1 then all the