From patchwork Fri Sep 2 18:58:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Aur=C3=A9lien_Aptel?= X-Patchwork-Id: 9311533 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7EB4860760 for ; Fri, 2 Sep 2016 19:20:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5FD7829834 for ; Fri, 2 Sep 2016 19:20:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4FA4B29850; Fri, 2 Sep 2016 19:20:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_TVD_MIME_EPI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A984929834 for ; Fri, 2 Sep 2016 19:20:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932209AbcIBTUf (ORCPT ); Fri, 2 Sep 2016 15:20:35 -0400 Received: from smtp.nue.novell.com ([195.135.221.5]:55019 "EHLO smtp.nue.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932197AbcIBTT0 (ORCPT ); Fri, 2 Sep 2016 15:19:26 -0400 Received: from nwb-ext-pat.microfocus.com ([10.120.13.103]) by smtp.nue.novell.com with ESMTP (TLS encrypted); Fri, 02 Sep 2016 20:58:23 +0200 Received: from localhost (nwb-a10-snat.microfocus.com [10.120.13.202]) by nwb-ext-pat.microfocus.com with ESMTP (TLS encrypted); Fri, 02 Sep 2016 19:58:12 +0100 From: =?utf-8?Q?Aur=C3=A9lien?= Aptel To: Stanislav Brabec Cc: util-linux , linux-cifs@vger.kernel.org, Steve French Subject: Re: [PATCH] libmount: Special handling of root comparison for cifs in mnt_table_is_fs_mounted() In-Reply-To: References: <91d465d3-4f5b-6270-a6c5-38bd94695731@suse.cz> <5eb96b3e-d463-bf11-49de-f614247d6b29@suse.cz> <20160805192234.2c9d5b7d@aaptelpc> <7c2181d1-c7b5-df04-0640-ec23f5d78eab@suse.cz> User-Agent: Notmuch/0.21 (http://notmuchmail.org) Emacs/24.5.1 (x86_64-unknown-linux-gnu) Date: Fri, 02 Sep 2016 20:58:08 +0200 Message-ID: MIME-Version: 1.0 Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi Stanislav, I've looked more into it and I found some issues with the patch: Stanislav Brabec writes: > + while ((c = *subpath++)) ^^^ subpath is always post-incremented > + { > + if (c == '/') { > + if (!last_is_slash) { > + component_no++; > + if (component_no == 3) > + break; ^^^ when we break subpath actually 1 past the / > + } > + last_is_slash = true; > + } else > + last_is_slash = false; > + } > + if (component_no == 3) { > + int subpath_len = strlen(subpath); > + if (strncmp(root, subpath, subpath_len)) { ^^^ ^^^ hence why here with //localhost/share/dir in fstab we never get here p root => $1 = 0x7f28aa9977d0 "/dir" p subpath => $2 = 0x7f28aa9979a2 "dir" > + if (*(root + subpath_len + 1) == 0) > + return "/"; > + return root + subpath_len + 1; > + } > + } > + DBG(FS, ul_debugobj(fs, "cifs: leading part of root \"%s\" does > not equal to mounted source subdir \"%s\"; should not happen", root, > src)); ^^^ this message gets printed with //localhost/share //localhost/share/ That being said, I could not make your patch fail i.e. make mount -a mount the fs twice. So I'm not sure what happens there... I thought I would give it a try. I'm attaching a simpler patch that makes uses of streq_paths() in lib/strutils.c (Note: streq_paths() and next_path_segment() have to be backported for older versions of util-linux). From a29acba1a7c71cdbfc1cc98f2905bfaf19b97a29 Mon Sep 17 00:00:00 2001 From: Aurelien Aptel Date: Thu, 1 Sep 2016 13:57:42 +0200 Subject: [PATCH] libmount/src/tab.c: fix mount -a for cifs when mounting a cifs share, the src is actually an UNC path which can in in several forms: simple: //host/share, //host/share/ including subpath: //host/share/sub/path to check if the cifs fs is mounted we have to extract the subpath and compare *that* to the root. Signed-off-by: Aurelien Aptel --- libmount/src/tab.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/libmount/src/tab.c b/libmount/src/tab.c index 341e5e3..9c49ec8 100644 --- a/libmount/src/tab.c +++ b/libmount/src/tab.c @@ -1329,6 +1329,20 @@ err: } #endif /* HAVE_BTRFS_SUPPORT */ +static const char *get_cifs_unc_subdir_path (const char *unc) +{ + /* + * 1 or more slash: %*[/] + * 1 or more non-slash: %*[^/] + * number of byte read: %n + */ + int share_end = 0; + int r = sscanf(unc, "%*[/]%*[^/]%*[/]%*[^/]%n", &share_end); + if (r == EOF || share_end == 0) + return NULL; + return unc + share_end; +} + /* * tb: /proc/self/mountinfo * fs: filesystem @@ -1563,9 +1577,16 @@ int mnt_table_is_fs_mounted(struct libmnt_table *tb, struct libmnt_fs *fstab_fs) } if (root) { - const char *r = mnt_fs_get_root(fs); - if (!r || strcmp(r, root) != 0) - continue; + if (strcmp(mnt_fs_get_fstype(fs), "cifs") == 0) { + const char *unc_subdir = get_cifs_unc_subdir_path(src); + const char *path_on_fs = mnt_fs_get_root(fs); + if (!unc_subdir || !path_on_fs || !streq_paths(unc_subdir, path_on_fs)) + continue; + } else { + const char *r = mnt_fs_get_root(fs); + if (!r || strcmp(r, root) != 0) + continue; + } } /* -- 2.1.4