Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp500280pxb; Thu, 17 Feb 2022 08:28:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJwPeojoCB3z580NQ8f2aH5+bsMKUU3FDHC9UYl0tuUQ7ym1XUQoLrLpe5mWc6FmVl0JVAod X-Received: by 2002:a05:6a00:1744:b0:4c4:4bd:dc17 with SMTP id j4-20020a056a00174400b004c404bddc17mr3576261pfc.57.1645115307521; Thu, 17 Feb 2022 08:28:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645115307; cv=none; d=google.com; s=arc-20160816; b=YGXBGL0oZmB2rd/6CyJn63jA0QP97XvjdHRqqtSPblf7xbMEWn4Nosn0pU65o4u02a Jx11kgRT62ODkwnFm0CqQpr20vk5vBh2XcmmQYgnlkoZBvFVuj/Urfsiz2WiDzt3ZMHE IPvVdUi/9FGVVFzF1xSKiua3yavzqkthKTeb7ophFrtEltQjnBRkv+7T6mHhnSiv4OHa ZKga+j9XGnxmxDYcBNVPqbSwUnm6sD+TCxihiB3bMT8BdfL24zu7oMpZwHlv8ucERAFg e79rP0/Ra2+pHvsd/nYfR+zLs5wdAvTryLrruqJWDsNx59cdVrfOXO9Xbmrwlwn/g7DY jxhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=KfnljbeytBoiCfJBcKZchBHYKkiaqWX0bXWcTlqtaGw=; b=b+stGq5TSh0bA2KE8/QrSSP+fq32w1gVPnQRzDRLJwOSufblPkhSu/e3yM7FBSYgTq yDd6fEbUnTMFy8gH5rB0XLEx8brk1eEbYO8HzJIoXz3LE0C8ZoS0rQtKFqIWMtxAQRAN GfjRt8zNSJo//Umeexx5R/ibQnOnqIZP9sU/3DEUsdhfyTYW+OJ99C9OEEPSO7n+VNuW L/tDc/0Mza+WAMio6FyBaSSWCbyE6IPrfR240Unf0YUmumVGvhmuvNWVptwIOyevqPTv kFmKuBTP/UPQm2KMMzC1JNq07g8FTmSrXKOPWm2JYnzXe71gpsKcDSufzBkz4QozIEnJ kyZQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e125si8994324pgc.165.2022.02.17.08.28.11; Thu, 17 Feb 2022 08:28:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238854AbiBQNXL (ORCPT + 99 others); Thu, 17 Feb 2022 08:23:11 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:51030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230153AbiBQNXJ (ORCPT ); Thu, 17 Feb 2022 08:23:09 -0500 Received: from lithops.sigma-star.at (lithops.sigma-star.at [195.201.40.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA54399ECE for ; Thu, 17 Feb 2022 05:22:52 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id A7713605DEBB; Thu, 17 Feb 2022 14:16:41 +0100 (CET) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id epkojYBpEXMZ; Thu, 17 Feb 2022 14:16:41 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by lithops.sigma-star.at (Postfix) with ESMTP id 030CD60765A6; Thu, 17 Feb 2022 14:16:41 +0100 (CET) Received: from lithops.sigma-star.at ([127.0.0.1]) by localhost (lithops.sigma-star.at [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id u5LINtTGGjJ2; Thu, 17 Feb 2022 14:16:40 +0100 (CET) Received: from blindfold.corp.sigma-star.at (213-47-184-186.cable.dynamic.surfer.at [213.47.184.186]) by lithops.sigma-star.at (Postfix) with ESMTPSA id 5D644605DED6; Thu, 17 Feb 2022 14:16:40 +0100 (CET) From: Richard Weinberger To: linux-nfs@vger.kernel.org Cc: david@sigma-star.at, bfields@fieldses.org, luis.turcitu@appsbroker.com, david.young@appsbroker.com, david.oberhollenzer@sigma-star.at, trond.myklebust@hammerspace.com, anna.schumaker@netapp.com, chris.chilvers@appsbroker.com, Richard Weinberger Subject: [RFC PATCH 6/6] export: Garbage collect orphaned subvolumes upon start Date: Thu, 17 Feb 2022 14:15:31 +0100 Message-Id: <20220217131531.2890-7-richard@nod.at> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220217131531.2890-1-richard@nod.at> References: <20220217131531.2890-1-richard@nod.at> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE,T_SPF_PERMERROR autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Make sure the database contains no orphaned subvolumes. We have to be careful. Signed-off-by: Richard Weinberger --- support/export/cache.c | 97 +++++++++++++++++++++++++++++++++++++++++ support/export/export.h | 3 ++ utils/exportd/exportd.c | 17 +++++++- utils/mountd/mountd.c | 1 + utils/mountd/svc_run.c | 18 ++++++++ 5 files changed, 135 insertions(+), 1 deletion(-) diff --git a/support/export/cache.c b/support/export/cache.c index b5763b1d..94a0d79a 100644 --- a/support/export/cache.c +++ b/support/export/cache.c @@ -1181,6 +1181,103 @@ lookup_export(char *dom, char *path, struct addri= nfo *ai) return found; } =20 +static char *get_export_path(char *path) +{ + int i; + nfs_export *exp; + nfs_export *found =3D NULL; + + for (i =3D 0; i < MCL_MAXTYPES; i++) { + for (exp =3D exportlist[i].p_head; exp; exp =3D exp->m_next) { + if (!path_matches(exp, path)) + continue; + + if (!found) { + found =3D exp; + continue; + } + + /* Always prefer non-V4ROOT exports */ + if (exp->m_export.e_flags & NFSEXP_V4ROOT) + continue; + if (found->m_export.e_flags & NFSEXP_V4ROOT) { + found =3D exp; + continue; + } + + /* If one is a CROSSMOUNT, then prefer the longest path */ + if (((found->m_export.e_flags & NFSEXP_CROSSMOUNT) || + (exp->m_export.e_flags & NFSEXP_CROSSMOUNT)) && + strlen(found->m_export.e_path) !=3D + strlen(exp->m_export.e_path)) { + + if (strlen(exp->m_export.e_path) > + strlen(found->m_export.e_path)) { + found =3D exp; + } + continue; + } + } + } + + if (found) + return found->m_export.e_path; + else + return NULL; +} + +int export_subvol_orphaned(char *path) +{ + struct statfs st, stp; + char *path_parent; + int ret; + + path_parent =3D get_export_path(path); + if (!path_parent) + /* + * Path has no parent in export list. + * Must be orphaned. + */ + return 1; + + ret =3D statfs(path_parent, &stp); + if (ret =3D=3D -1) + /* + * Parent path is not statfs'able. Maybe not yet mounted? + * Can't be sure, don't treat path as orphaned. + */ + return 0; + + if (strcmp(path_parent, path) =3D=3D 0) + /* + * This is not a subvolume, it is listed in exports. + * No need to keep tack of it. + */ + return 1; + + if (stp.f_type !=3D 0x6969) + /* + * Parent is not a NFS mount. Maybe not yet mounted? + * Can't be sure either. + */ + return 0; + + ret =3D statfs(path, &st); + if (ret =3D=3D -1) { + if (errno =3D=3D ENOENT) + /* + * Parent is a NFS mount but path is gone. + * Must be orphaned. + */ + return 1; + } + + /* + * For all remaining cases we can't be sure either. + */ + return 0; +} + #ifdef HAVE_JUNCTION_SUPPORT =20 #include diff --git a/support/export/export.h b/support/export/export.h index 8d5a0d30..45dd3da4 100644 --- a/support/export/export.h +++ b/support/export/export.h @@ -38,4 +38,7 @@ static inline bool is_ipaddr_client(char *dom) { return dom[0] =3D=3D '$'; } + +int export_subvol_orphaned(char *path); + #endif /* EXPORT__H */ diff --git a/utils/exportd/exportd.c b/utils/exportd/exportd.c index 4ddfed35..6dc51a32 100644 --- a/utils/exportd/exportd.c +++ b/utils/exportd/exportd.c @@ -208,6 +208,12 @@ read_exportd_conf(char *progname, char **argv) default_ttl =3D ttl; } =20 +static void subvol_cb(char *path) +{ + if (export_subvol_orphaned(path)) + reexpdb_drop_subvolume_unlocked(path); +} + int main(int argc, char **argv) { @@ -297,7 +303,16 @@ main(int argc, char **argv) /* Open files now to avoid sharing descriptors among forked processes *= / cache_open(); v4clients_init(); - reexpdb_init(); + if (reexpdb_init() !=3D 0) { + xlog(L_ERROR, "%s: Failed to init reexport database", __func__); + exit(1); + } + + /* + * Load exports into memory and garbage collect orphaned subvolumes. + */ + auth_reload(); + reexpdb_uncover_subvolumes(subvol_cb); =20 /* Process incoming upcalls */ cache_process_loop(); diff --git a/utils/mountd/mountd.c b/utils/mountd/mountd.c index bcf749fa..8555d746 100644 --- a/utils/mountd/mountd.c +++ b/utils/mountd/mountd.c @@ -32,6 +32,7 @@ #include "nfsd_path.h" #include "nfslib.h" #include "export.h" +#include "reexport.h" =20 extern void my_svc_run(void); =20 diff --git a/utils/mountd/svc_run.c b/utils/mountd/svc_run.c index 167b9757..9a891ff0 100644 --- a/utils/mountd/svc_run.c +++ b/utils/mountd/svc_run.c @@ -57,6 +57,7 @@ #include #endif #include "export.h" +#include "reexport.h" =20 void my_svc_run(void); =20 @@ -87,6 +88,12 @@ my_svc_getreqset (fd_set *readfds) =20 #endif =20 +static void subvol_cb(char *path) +{ + if (export_subvol_orphaned(path)) + reexpdb_drop_subvolume_unlocked(path); +} + /* * The heart of the server. A crib from libc for the most part... */ @@ -96,6 +103,17 @@ my_svc_run(void) fd_set readfds; int selret; =20 + if (reexpdb_init() !=3D 0) { + xlog(L_ERROR, "%s: Failed to init reexport database", __func__); + return; + } + + /* + * Load exports into memory and garbage collect orphaned subvolumes. + */ + auth_reload(); + reexpdb_uncover_subvolumes(subvol_cb); + for (;;) { =20 readfds =3D svc_fdset; --=20 2.31.1