From 56692e77e2178e9af977ca8bbf99a664df002f3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Tue, 22 Mar 2022 15:50:46 +0100 Subject: [PATCH] linux: libshare: smb: fix more than one smb_is_share_active() call MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This also fixes zfs_unshare_006_pos, which exposed this Fixes: 2f71caf2d926249920d1b9162550c56715cc6461 ("Allow zfs unshare -a") Reviewed-by: Brian Behlendorf Reviewed-by: John Kennedy Reviewed-by: Ryan Moeller Signed-off-by: Ahelenia ZiemiaƄska Closes #13259 --- lib/libshare/os/linux/smb.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/lib/libshare/os/linux/smb.c b/lib/libshare/os/linux/smb.c index bcb9b427031f..47d1aa776c4f 100644 --- a/lib/libshare/os/linux/smb.c +++ b/lib/libshare/os/linux/smb.c @@ -323,8 +323,6 @@ smb_disable_share_one(const char *sharename) static int smb_disable_share(sa_share_impl_t impl_share) { - smb_share_t *shares = smb_shares; - if (!smb_available()) { /* * The share can't possibly be active, so nothing @@ -333,12 +331,9 @@ smb_disable_share(sa_share_impl_t impl_share) return (SA_OK); } - while (shares != NULL) { - if (strcmp(impl_share->sa_mountpoint, shares->path) == 0) - return (smb_disable_share_one(shares->name)); - - shares = shares->next; - } + for (const smb_share_t *i = smb_shares; i != NULL; i = i->next) + if (strcmp(impl_share->sa_mountpoint, i->path) == 0) + return (smb_disable_share_one(i->name)); return (SA_OK); } @@ -362,21 +357,16 @@ smb_validate_shareopts(const char *shareopts) static boolean_t smb_is_share_active(sa_share_impl_t impl_share) { - smb_share_t *iter = smb_shares; - if (!smb_available()) return (B_FALSE); /* Retrieve the list of (possible) active shares */ smb_retrieve_shares(); - while (iter != NULL) { - if (strcmp(impl_share->sa_mountpoint, iter->path) == 0) + for (const smb_share_t *i = smb_shares; i != NULL; i = i->next) + if (strcmp(impl_share->sa_mountpoint, i->path) == 0) return (B_TRUE); - iter = iter->next; - } - return (B_FALSE); }