Skip to content

Commit bf0b131

Browse files
committed
Misc iSCSI fixes/cleanups/attempts to get 'zfs rename' to work.
!! Doesn't - a 'zfs rename' works, but most often than not, the rename !! IOCTL hangs. Not every time and not always on the first dataset being !! renamed... Seems a little to random to me.
1 parent add68b8 commit bf0b131

File tree

2 files changed

+30
-26
lines changed

2 files changed

+30
-26
lines changed

lib/libzfs/libzfs_changelist.c

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ changelist_prefix(prop_changelist_t *clp)
101101
int ret = 0;
102102

103103
if (clp->cl_prop != ZFS_PROP_MOUNTPOINT &&
104-
clp->cl_prop != ZFS_PROP_SHARESMB)
104+
clp->cl_prop != ZFS_PROP_SHARESMB &&
105+
clp->cl_prop != ZFS_PROP_SHAREISCSI)
105106
return (0);
106107

107108
for (cn = uu_list_first(clp->cl_list); cn != NULL;
@@ -139,6 +140,17 @@ changelist_prefix(prop_changelist_t *clp)
139140
default:
140141
break;
141142
}
143+
} else if (ZFS_IS_VOLUME(cn->cn_handle) && cn->cn_shared &&
144+
clp->cl_realprop == ZFS_PROP_NAME) {
145+
/* If this was a rename, unshare the zvol */
146+
147+
/*
148+
* XXX: Sometimes (quite often actually), the rename
149+
* IOCTL that follows hangs (because of this?
150+
* - works without it, but the old share won't
151+
* get removed/unshared)...
152+
*/
153+
(void) zfs_unshare_iscsi(cn->cn_handle, NULL);
142154
}
143155
}
144156

@@ -240,9 +252,9 @@ changelist_postfix(prop_changelist_t *clp)
240252

241253
mounted = zfs_is_mounted(cn->cn_handle, NULL);
242254

243-
if (!mounted && (cn->cn_mounted ||
244-
((sharenfs || sharesmb || shareiscsi ||
245-
clp->cl_waslegacy) && (zfs_prop_get_int(cn->cn_handle,
255+
if (!mounted && !needs_key && (cn->cn_mounted ||
256+
((sharenfs || sharesmb || clp->cl_waslegacy) &&
257+
(zfs_prop_get_int(cn->cn_handle,
246258
ZFS_PROP_CANMOUNT) == ZFS_CANMOUNT_ON)))) {
247259
if (zfs_mount(cn->cn_handle, NULL, 0) != 0)
248260
errors++;
@@ -255,26 +267,10 @@ changelist_postfix(prop_changelist_t *clp)
255267
* if the filesystem is currently shared, so that we can
256268
* adopt any new options.
257269
*/
258-
if (sharenfs && mounted)
259-
errors += zfs_share_nfs(cn->cn_handle);
270+
if (((sharenfs || sharesmb) && mounted) || shareiscsi)
271+
errors += zfs_share(cn->cn_handle);
260272
else if (cn->cn_shared || clp->cl_waslegacy)
261-
errors += zfs_unshare_nfs(cn->cn_handle, NULL);
262-
if (sharesmb && mounted)
263-
errors += zfs_share_smb(cn->cn_handle);
264-
else if (cn->cn_shared || clp->cl_waslegacy)
265-
errors += zfs_unshare_smb(cn->cn_handle, NULL);
266-
267-
/*
268-
* XXX: This is wrong somehow - needs to be fixed properly.
269-
* In practice it works, it just looks wrong (considering
270-
* above code...
271-
*/
272-
if (shareiscsi && !cn->cn_shared)
273-
errors += zfs_share_iscsi(cn->cn_handle);
274-
if (cn->cn_shared) {
275-
errors += zfs_unshare_iscsi(cn->cn_handle, NULL);
276-
errors += zfs_share_iscsi(cn->cn_handle);
277-
}
273+
errors += zfs_unshare(cn->cn_handle);
278274
}
279275

280276
return (errors ? -1 : 0);
@@ -572,7 +568,7 @@ changelist_gather(zfs_handle_t *zhp, zfs_prop_t prop, int gather_flags,
572568
*/
573569
if (prop == ZFS_PROP_NAME || prop == ZFS_PROP_ZONED ||
574570
prop == ZFS_PROP_MOUNTPOINT || prop == ZFS_PROP_SHARENFS ||
575-
prop == ZFS_PROP_SHARESMB || prop == ZFS_PROP_SHAREISCSI) {
571+
prop == ZFS_PROP_SHARESMB) {
576572

577573
if (zfs_prop_get(zhp, ZFS_PROP_MOUNTPOINT,
578574
property, sizeof (property),
@@ -641,7 +637,7 @@ changelist_gather(zfs_handle_t *zhp, zfs_prop_t prop, int gather_flags,
641637
return (clp);
642638

643639
/*
644-
* If watching SHARENFS, SHARESMB then
640+
* If watching SHARENFS or SHARESMB then
645641
* also watch its companion property.
646642
*/
647643
/* TODO: add SHAREISCSI ? */

lib/libzfs/libzfs_dataset.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4340,7 +4340,15 @@ zfs_rename(zfs_handle_t *zhp, const char *target, boolean_t recursive,
43404340
if (cl != NULL)
43414341
(void) changelist_postfix(cl);
43424342
} else {
4343-
if (cl != NULL) {
4343+
if (cl != NULL && !recursive) {
4344+
/*
4345+
* XXX: This 'removes' the old ZVOL name from the
4346+
* list, making changelist_postfix() not
4347+
* removing the old share, which leaves
4348+
* TWO shares - the old and the new!
4349+
*
4350+
* But why does it work for NFS and SMB!?
4351+
*/
43444352
changelist_rename(cl, zfs_get_name(zhp), target);
43454353
ret = changelist_postfix(cl);
43464354
}

0 commit comments

Comments
 (0)