From patchwork Fri Oct 19 08:03:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianhong Yin X-Patchwork-Id: 10648789 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B3BA615E2 for ; Fri, 19 Oct 2018 08:04:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A595728A34 for ; Fri, 19 Oct 2018 08:04:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9865928A39; Fri, 19 Oct 2018 08:04:03 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 4055F28A34 for ; Fri, 19 Oct 2018 08:04:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726790AbeJSQI7 (ORCPT ); Fri, 19 Oct 2018 12:08:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:9962 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726758AbeJSQI7 (ORCPT ); Fri, 19 Oct 2018 12:08:59 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 04E7A300127A; Fri, 19 Oct 2018 08:04:02 +0000 (UTC) Received: from dhcp-12-115.nay.redhat.com (dhcp-12-115.nay.redhat.com [10.66.12.115]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8BC773416A; Fri, 19 Oct 2018 08:04:00 +0000 (UTC) From: jiyin@redhat.com To: steved@redhat.com Cc: linux-nfs@vger.kernel.org, "Jianhong.Yin" Subject: [PATCH] [nfs-utils] fix issue: mount -osharecache failure but return 'true' Date: Fri, 19 Oct 2018 16:03:54 +0800 Message-Id: <20181019080354.26141-1-jiyin@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Fri, 19 Oct 2018 08:04:02 +0000 (UTC) Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: "Jianhong.Yin" see: https://bugzilla.redhat.com/show_bug.cgi?id=1629705 mount.nfs4 -o context=system_u:object_r:user_home_dir_t:s0,sharecache $serv:$expdir $nfsmp mount.nfs4 -o context=system_u:object_r:xferlog_t:s0,sharecache $serv:$expdir $nfsmp2 ^^^ here mount fail, but return true. it confuse user! according: https://patchwork.kernel.org/patch/10602607/#22234047 add function is_mounted_already() - if (errno == EBUSY) + if (errno == EBUSY && is_mounted_already(mi->spec, mi->node)) return EX_SUCCESS; Signed-off-by: Jianhong Yin --- utils/mount/stropts.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/utils/mount/stropts.c b/utils/mount/stropts.c index 4d2e37e..4be7e61 100644 --- a/utils/mount/stropts.c +++ b/utils/mount/stropts.c @@ -48,6 +48,7 @@ #include "version.h" #include "parse_dev.h" #include "conffile.h" +#include #ifndef NFS_PROGRAM #define NFS_PROGRAM (100003) @@ -1056,6 +1057,27 @@ static int nfs_is_permanent_error(int error) } } +static int is_mounted_already(const char *fsname, const char *dir) +{ + struct mntent *ent; + FILE *fp; + int ret = 0; + + fp = setmntent("/proc/mounts", "r"); + if (fp == NULL) { + perror("[unlikely] setmntent(3) fail"); + exit(1); + } + while (NULL != (ent = getmntent(fp))) { + if (!strcmp(ent->mnt_fsname, fsname) && !strcmp(ent->mnt_dir, dir)) { + ret = 1; + break; + } + } + endmntent(fp); + return ret; +} + /* * Handle "foreground" NFS mounts. * @@ -1078,13 +1100,8 @@ static int nfsmount_fg(struct nfsmount_info *mi) if (nfs_try_mount(mi)) return EX_SUCCESS; - if (errno == EBUSY) - /* The only cause of EBUSY is if exactly the desired - * filesystem is already mounted. That can arguably - * be seen as success. "mount -a" tries to optimise - * out this case but sometimes fails. Help it out - * by pretending everything is rosy - */ + /* if EBUSY is caused by re-mount, ignore the error */ + if (errno == EBUSY && is_mounted_already(mi->spec, mi->node)) return EX_SUCCESS; if (nfs_is_permanent_error(errno))