}
Volume *
-VCreateVolume(Error * ec, char *partname, VolId volumeId, VolId parentId)
+VCreateVolume(Error * ec, char *partname, VolumeId volumeId, VolumeId parentId)
{ /* Should be the same as volumeId if there is
* no parent */
Volume *retVal;
}
Volume *
-VCreateVolume_r(Error * ec, char *partname, VolId volumeId, VolId parentId)
+VCreateVolume_r(Error * ec, char *partname, VolumeId volumeId, VolumeId parentId)
{ /* Should be the same as volumeId if there is
* no parent */
VolumeDiskData vol;
int i, rc;
- char headerName[VMAXPATHLEN], volumePath[VMAXPATHLEN];
+ char headerName[VMAXPATHLEN], volumePath[VMAXPATHLEN + 1];
Device device;
struct DiskPartition64 *partition;
struct VolumeDiskHeader diskHeader;
if (*ec == VNOVOL || !strcmp(partition->name, part)) {
/* this case is ok */
} else {
- /* return EXDEV if it's a clone to an alternate partition
+ /* return EXDEV if it's a clone or read-only to an alternate partition
* otherwise assume it's a move */
if (vol.parentId != vol.id) {
+ Log("VCreateVolume: volume %" AFS_VOLID_FMT " for parent %" AFS_VOLID_FMT
+ " found on %s; unable to create volume on %s.\n",
+ afs_printable_VolumeId_lu(vol.id),
+ afs_printable_VolumeId_lu(vol.parentId), part, partition->name);
*ec = EXDEV;
return NULL;
}
vol.stamp.version = VOLUMEINFOVERSION;
vol.destroyMe = DESTROY_ME;
snprintf(headerName, sizeof headerName, VFORMAT,
- afs_printable_uint32_lu(vol.id));
+ afs_printable_VolumeId_lu(vol.id));
snprintf(volumePath, sizeof volumePath, "%s" OS_DIRSEP "%s",
VPartitionPath(partition), headerName);
rc = stat(volumePath, &st);
rc = VCreateVolumeDiskHeader(&diskHeader, partition);
if (rc) {
Log("VCreateVolume: Error %d trying to write volume header for "
- "volume %u on partition %s; volume not created\n", rc,
- vol.id, VPartitionPath(partition));
+ "volume %" AFS_VOLID_FMT " on partition %s; volume not created\n", rc,
+ afs_printable_VolumeId_lu(vol.id), VPartitionPath(partition));
if (rc == EEXIST) {
*ec = VVOLEXISTS;
}
char path[MAXPATHLEN];
snprintf(path, sizeof(path), "%s" OS_DIRSEP VFORMAT,
- VPartitionPath(dp), afs_printable_uint32_lu(volid));
+ VPartitionPath(dp), afs_printable_VolumeId_lu(volid));
fd = open(path, O_RDONLY);
if (fd < 0) {
- Log("VReadVolumeDiskHeader: Couldn't open header for volume %lu (errno %d).\n",
- afs_printable_uint32_lu(volid), errno);
+ Log("VReadVolumeDiskHeader: Couldn't open header for volume %" AFS_VOLID_FMT " (errno %d).\n",
+ afs_printable_VolumeId_lu(volid), errno);
code = -1;
} else if (hdr && read(fd, hdr, sizeof(*hdr)) != sizeof(*hdr)) {
- Log("VReadVolumeDiskHeader: Couldn't read header for volume %lu.\n",
- afs_printable_uint32_lu(volid));
+ Log("VReadVolumeDiskHeader: Couldn't read header for volume %" AFS_VOLID_FMT ".\n",
+ afs_printable_VolumeId_lu(volid));
code = EIO;
}
flags |= O_RDWR;
snprintf(path, sizeof(path), "%s" OS_DIRSEP VFORMAT,
- VPartitionPath(dp), afs_printable_uint32_lu(hdr->id));
+ VPartitionPath(dp), afs_printable_VolumeId_lu(hdr->id));
fd = open(path, flags, 0644);
if (fd < 0) {
code = errno;
* @return operation status
* @retval 0 success
*
- * @note if parent is 0, the parent volume ID will be looked up from the
- * fileserver
- *
* @note for non-DAFS, parent is currently ignored
*/
afs_int32
#endif /* AFS_DEMAND_ATTACH_FS */
snprintf(path, sizeof(path), "%s" OS_DIRSEP VFORMAT,
- VPartitionPath(dp), afs_printable_uint32_lu(volid));
+ VPartitionPath(dp), afs_printable_VolumeId_lu(volid));
code = unlink(path);
if (code) {
Log("VDestroyVolumeDiskHeader: Couldn't unlink disk header, error = %d\n", errno);
}
#ifdef AFS_DEMAND_ATTACH_FS
+ /* Remove the volume entry from the fileserver's volume group cache, if found. */
memset(&res, 0, sizeof(res));
- if (!parent) {
- FSSYNC_VGQry_response_t q_res;
-
- code = FSYNC_VGCQuery(dp->name, volid, &q_res, &res);
- if (code) {
- Log("VDestroyVolumeDiskHeader: FSYNC_VGCQuery(%s, %lu) failed "
- "with code %ld, reason %ld\n", dp->name,
- afs_printable_uint32_lu(volid), afs_printable_int32_ld(code),
- afs_printable_int32_ld(res.hdr.reason));
- goto done;
- }
-
- parent = q_res.rw;
-
- }
code = FSYNC_VGCDel(dp->name, parent, volid, FSYNC_WHATEVER, &res);
if (code) {
- Log("VDestroyVolumeDiskHeader: FSYNC_VGCDel(%s, %lu, %lu) failed "
+ Log("VDestroyVolumeDiskHeader: FSYNC_VGCDel(%s, %" AFS_VOLID_FMT ", %" AFS_VOLID_FMT ") failed "
"with code %ld reason %ld\n", dp->name,
- afs_printable_uint32_lu(parent),
- afs_printable_uint32_lu(volid),
+ afs_printable_VolumeId_lu(parent),
+ afs_printable_VolumeId_lu(volid),
afs_printable_int32_ld(code),
afs_printable_int32_ld(res.hdr.reason));
}
if (p != NULL && strcmp(p, VHDREXT) == 0) {
char name[VMAXPATHLEN];
- sprintf(name, "%s" OS_DIRSEP "%s", partpath, dentry->d_name);
+ snprintf(name, VMAXPATHLEN, "%s" OS_DIRSEP "%s", partpath, dentry->d_name);
code = _VHandleVolumeHeader(dp, volfunc, name, &diskHeader, -1, rock);
if (code < 0) {
int cmd = AFS_SETLKW;
struct afs_st_flock sf;
+ opr_Assert(fd >= 0);
+
if (locktype == READ_LOCK) {
l_type = F_RDLCK;
}
opr_mutex_enter(&lf->mutex);
if (lf->fd == INVALID_FD) {
+ opr_Assert(lf->refcount == 0);
lf->fd = _VOpenPath(lf->path);
if (lf->fd == INVALID_FD) {
opr_mutex_exit(&lf->mutex);
lf->refcount++;
+ opr_Assert(lf->refcount > 0);
+
opr_mutex_exit(&lf->mutex);
code = _VLockFd(lf->fd, offset, locktype, nonblock);
if (code) {
opr_mutex_enter(&lf->mutex);
+ opr_Assert(lf->refcount > 0);
if (--lf->refcount < 1) {
_VCloseFd(lf->fd);
lf->fd = INVALID_FD;
opr_mutex_enter(&lf->mutex);
opr_Assert(lf->fd != INVALID_FD);
+ opr_Assert(lf->refcount > 0);
if (--lf->refcount < 1) {
_VCloseFd(lf->fd);