From patchwork Tue Jun 11 18:08:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10988107 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 7BB6D1708 for ; Tue, 11 Jun 2019 18:12:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6CA5E28355 for ; Tue, 11 Jun 2019 18:12:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 60CAD2856F; Tue, 11 Jun 2019 18:12:04 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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 7F9F82858E for ; Tue, 11 Jun 2019 18:12:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406913AbfFKSMC (ORCPT ); Tue, 11 Jun 2019 14:12:02 -0400 Received: from mail-io1-f65.google.com ([209.85.166.65]:34697 "EHLO mail-io1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406884AbfFKSMB (ORCPT ); Tue, 11 Jun 2019 14:12:01 -0400 Received: by mail-io1-f65.google.com with SMTP id k8so10720831iot.1 for ; Tue, 11 Jun 2019 11:12:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=JXL+v9gwEGJ1PNf5Y/zoPLJPvp6gT/aSy8aczFGnbhU=; b=VVDLUPsoCawBKwMkcrAYyu+2upqZODAyZ0bWYSsoQRXUyLz/xxwRHOfh42EFtsqH1c H3gdOl5MO+QrGfoADrKY6P1mcK4tvtRRrxpT8OU9MJupDurN36eb4KiYp/SWRlIURaX/ z/dpyOBWRTT2Ko49qhpQKOXLgQuCAMTfDOKGGAi7Z8sbFhImkB2Zn5xAFx1ACkdTVOGX SL0AqzwRb6ylE+6AYohiQWrrToKhNaCuOSFr2zacH3NCjfDC56o/b3QWenIz7Dstgd4u hf96BKR7cWQAId8UY8Z49zSdFmtehEOzf7KDbBcfC5JWtpopV/7Oj+7FvXPv76NG5OUV VLRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JXL+v9gwEGJ1PNf5Y/zoPLJPvp6gT/aSy8aczFGnbhU=; b=CFLuIKV+gG+7wxNwUk79RIK2k/+PRZV0Rnsh8b0DDn+u688AzFGOE4q12I9hMHOoMb 8kJAoQ3M5sr0v26GSgkldVNQKHqIrfvgpMVZ+hWsv0BC1iHFC9OdEc8IKcAapjKPfBKP t/jR2ahdnLzdTYTisbUbaxFJxdIjMzCBJGGcXGfx6Jo8X9SHZd3MfZjl3krYNVtIuBgS xdihL/uyYsMnP91fJXMtq4o1xfA382Ykp4+IXHo6yPGjXdFdCNbjgZzncvUO1ifGNNGX UMZyuqKFPOl+hYeb0kh1On9edXdE+lSSHWyOr3FGI+vvb9a1tnOyUDfP0SWoBlUewzf3 CoKA== X-Gm-Message-State: APjAAAVrLqKH+XZxysD0aHtmpRTNMTVtfYub323wVZBCw8cNAnBYbuPV snq0BsfNTSJwD9NHZ+CeSI93OTQ= X-Google-Smtp-Source: APXvYqwNDk/ik5tMrL92dxWyxmY92/i7795FTTEeLCQn6ZQj9iOydCk0He0UIKuAHC+SRu64whUbcg== X-Received: by 2002:a5d:8c81:: with SMTP id g1mr6151387ion.239.1560276720137; Tue, 11 Jun 2019 11:12:00 -0700 (PDT) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id f4sm4900212iok.56.2019.06.11.11.11.59 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 11 Jun 2019 11:11:59 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: linux-nfs@vger.kernel.org Subject: [PATCH 1/3] NFS: Create a root NFS directory in /sys/fs/nfs Date: Tue, 11 Jun 2019 14:08:30 -0400 Message-Id: <20190611180832.119488-2-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190611180832.119488-1-trond.myklebust@hammerspace.com> References: <20190611180832.119488-1-trond.myklebust@hammerspace.com> MIME-Version: 1.0 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 Signed-off-by: Trond Myklebust --- fs/nfs/Makefile | 3 ++- fs/nfs/inode.c | 8 ++++++ fs/nfs/sysfs.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++ fs/nfs/sysfs.h | 15 +++++++++++ 4 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 fs/nfs/sysfs.c create mode 100644 fs/nfs/sysfs.h diff --git a/fs/nfs/Makefile b/fs/nfs/Makefile index c587e3c4c6a6..34cdeaecccf6 100644 --- a/fs/nfs/Makefile +++ b/fs/nfs/Makefile @@ -8,7 +8,8 @@ obj-$(CONFIG_NFS_FS) += nfs.o CFLAGS_nfstrace.o += -I$(src) nfs-y := client.o dir.o file.o getroot.o inode.o super.o \ io.o direct.o pagelist.o read.o symlink.o unlink.o \ - write.o namespace.o mount_clnt.o nfstrace.o export.o + write.o namespace.o mount_clnt.o nfstrace.o \ + export.o sysfs.o nfs-$(CONFIG_ROOT_NFS) += nfsroot.o nfs-$(CONFIG_SYSCTL) += sysctl.o nfs-$(CONFIG_NFS_FSCACHE) += fscache.o fscache-index.o diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c index 0b4a1a974411..60b9e14a0309 100644 --- a/fs/nfs/inode.c +++ b/fs/nfs/inode.c @@ -51,6 +51,7 @@ #include "pnfs.h" #include "nfs.h" #include "netns.h" +#include "sysfs.h" #include "nfstrace.h" @@ -2181,6 +2182,10 @@ static int __init init_nfs_fs(void) { int err; + err = nfs_sysfs_init(); + if (err < 0) + goto out10; + err = register_pernet_subsys(&nfs_net_ops); if (err < 0) goto out9; @@ -2244,6 +2249,8 @@ static int __init init_nfs_fs(void) out8: unregister_pernet_subsys(&nfs_net_ops); out9: + nfs_sysfs_exit(); +out10: return err; } @@ -2260,6 +2267,7 @@ static void __exit exit_nfs_fs(void) unregister_nfs_fs(); nfs_fs_proc_exit(); nfsiod_stop(); + nfs_sysfs_exit(); } /* Not quite true; I just maintain it */ diff --git a/fs/nfs/sysfs.c b/fs/nfs/sysfs.c new file mode 100644 index 000000000000..7070711ff6c5 --- /dev/null +++ b/fs/nfs/sysfs.c @@ -0,0 +1,69 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2019 Hammerspace Inc + */ + +#include +#include +#include +#include +#include +#include + +#include "sysfs.h" + +struct kobject *nfs_client_kobj; +static struct kset *nfs_client_kset; + +static void nfs_netns_object_release(struct kobject *kobj) +{ + kfree(kobj); +} + +static const struct kobj_ns_type_operations *nfs_netns_object_child_ns_type( + struct kobject *kobj) +{ + return &net_ns_type_operations; +} + +static struct kobj_type nfs_netns_object_type = { + .release = nfs_netns_object_release, + .sysfs_ops = &kobj_sysfs_ops, + .child_ns_type = nfs_netns_object_child_ns_type, +}; + +static struct kobject *nfs_netns_object_alloc(const char *name, + struct kset *kset, struct kobject *parent) +{ + struct kobject *kobj; + + kobj = kzalloc(sizeof(*kobj), GFP_KERNEL); + if (kobj) { + kobj->kset = kset; + if (kobject_init_and_add(kobj, &nfs_netns_object_type, + parent, "%s", name) == 0) + return kobj; + kobject_put(kobj); + } + return NULL; +} + +int nfs_sysfs_init(void) +{ + nfs_client_kset = kset_create_and_add("nfs", NULL, fs_kobj); + if (!nfs_client_kset) + return -ENOMEM; + nfs_client_kobj = nfs_netns_object_alloc("net", nfs_client_kset, NULL); + if (!nfs_client_kobj) { + kset_unregister(nfs_client_kset); + nfs_client_kset = NULL; + return -ENOMEM; + } + return 0; +} + +void nfs_sysfs_exit(void) +{ + kobject_put(nfs_client_kobj); + kset_unregister(nfs_client_kset); +} diff --git a/fs/nfs/sysfs.h b/fs/nfs/sysfs.h new file mode 100644 index 000000000000..666f8db2ba92 --- /dev/null +++ b/fs/nfs/sysfs.h @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2019 Hammerspace Inc + */ + +#ifndef __NFS_SYSFS_H +#define __NFS_SYSFS_H + + +extern struct kobject *nfs_client_kobj; + +extern int nfs_sysfs_init(void); +extern void nfs_sysfs_exit(void); + +#endif From patchwork Tue Jun 11 18:08:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10988109 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 F032B76 for ; Tue, 11 Jun 2019 18:12:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E0A9C2857E for ; Tue, 11 Jun 2019 18:12:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D4C4428355; Tue, 11 Jun 2019 18:12:06 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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 6F8BE28355 for ; Tue, 11 Jun 2019 18:12:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406921AbfFKSMC (ORCPT ); Tue, 11 Jun 2019 14:12:02 -0400 Received: from mail-io1-f68.google.com ([209.85.166.68]:36200 "EHLO mail-io1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406685AbfFKSMC (ORCPT ); Tue, 11 Jun 2019 14:12:02 -0400 Received: by mail-io1-f68.google.com with SMTP id h6so10720696ioh.3 for ; Tue, 11 Jun 2019 11:12:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=YJLD8pEsKbKgJy30zP2LAtajfM+mMiPdYAfw6ctSvAU=; b=HtOMHpCm+eke4h2xs+WpRbfk+R9swPSDpjIZsmkksBVE8skw5JsG1m252MoJdDq3Gs O+qMzpN83ZqO68fhZ5ecxaE5+PuPUBanZQcka+z2wXul4VCdpPEZzPSjybW+MWcBlW0/ H70KR7iRppgssE5DmaZr7N2H1S186B3ieY8q5GXQStMDaRg6GROIbTTiiiQWQW78XkNR 6/GJju+5M8DyGWCYpjbwE+7cTF0sl68z2W2kZWbczzY8IJEBGIHSRMi7EZpaN39h4RWo OyOQNoyGR82a9OpUhJrPEOGuWqmhKxjzzl1ZsW3qoVaei1LyJ6NgJcI+4peM6J2hM4ty HaUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YJLD8pEsKbKgJy30zP2LAtajfM+mMiPdYAfw6ctSvAU=; b=GT5jLt5UBFQsHzmeqV5nsnpfkeqsPjwlCIZ+hIdDNC7qF5nbbVe5Zdd0fSXLi3Q9IA msIRaOHrCRQGFK6slH8lSNba0/039onPmQmveS3mfUUcjTUECpNDhoq+DUsjUDwdAEvI 72YN/xFEYIYeiVwz6prZGdb7/2eSkEUCSnihcD3SsIF9b0U4H9EYrUm82MWr85QPcRgW qMuuPbLqCz2yousQWdC78Ct9zPgMO7BK4qDWFnWHhCk/rRTR77N2lGQs31G6HYis6r4M mfR0N9IHs0faKKTSO7ox4PqtHlJAJZKMDYMgflLIzd0PFknwT7LXpo0+Pgpz/dXa1B11 GslA== X-Gm-Message-State: APjAAAUdXLaGMUjsTu60N0p1ltm176dyysd5pUzJ8oPctvE7rszGOYFP KvUdSNWRH7WrN1jEM/5b20jFZ5k= X-Google-Smtp-Source: APXvYqwPQ2f7uUrG7d0Ru70vuMo02okx9xvyLenWS+at7UQgC9DUXO6/1bRUZjofsh9FxkK3fcyU0Q== X-Received: by 2002:a5e:890f:: with SMTP id k15mr20772824ioj.121.1560276720756; Tue, 11 Jun 2019 11:12:00 -0700 (PDT) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id f4sm4900212iok.56.2019.06.11.11.12.00 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 11 Jun 2019 11:12:00 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: linux-nfs@vger.kernel.org Subject: [PATCH 2/3] NFS: Cleanup - add nfs_clients_exit to mirror nfs_clients_init Date: Tue, 11 Jun 2019 14:08:31 -0400 Message-Id: <20190611180832.119488-3-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190611180832.119488-2-trond.myklebust@hammerspace.com> References: <20190611180832.119488-1-trond.myklebust@hammerspace.com> <20190611180832.119488-2-trond.myklebust@hammerspace.com> MIME-Version: 1.0 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 Add a helper to clean up the struct nfs_net when it is being destroyed. Signed-off-by: Trond Myklebust --- fs/nfs/client.c | 13 +++++++++++-- fs/nfs/inode.c | 6 +----- fs/nfs/internal.h | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/fs/nfs/client.c b/fs/nfs/client.c index d7e4f0848e28..0acb104f7b00 100644 --- a/fs/nfs/client.c +++ b/fs/nfs/client.c @@ -192,7 +192,7 @@ struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_init) EXPORT_SYMBOL_GPL(nfs_alloc_client); #if IS_ENABLED(CONFIG_NFS_V4) -void nfs_cleanup_cb_ident_idr(struct net *net) +static void nfs_cleanup_cb_ident_idr(struct net *net) { struct nfs_net *nn = net_generic(net, nfs_net_id); @@ -214,7 +214,7 @@ static void pnfs_init_server(struct nfs_server *server) } #else -void nfs_cleanup_cb_ident_idr(struct net *net) +static void nfs_cleanup_cb_ident_idr(struct net *net) { } @@ -1074,6 +1074,15 @@ void nfs_clients_init(struct net *net) nn->boot_time = ktime_get_real(); } +void nfs_clients_exit(struct net *net) +{ + struct nfs_net *nn = net_generic(net, nfs_net_id); + + nfs_cleanup_cb_ident_idr(net); + WARN_ON_ONCE(!list_empty(&nn->nfs_client_list)); + WARN_ON_ONCE(!list_empty(&nn->nfs_volume_list)); +} + #ifdef CONFIG_PROC_FS static void *nfs_server_list_start(struct seq_file *p, loff_t *pos); static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos); diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c index 60b9e14a0309..dab410f3f5db 100644 --- a/fs/nfs/inode.c +++ b/fs/nfs/inode.c @@ -2160,12 +2160,8 @@ static int nfs_net_init(struct net *net) static void nfs_net_exit(struct net *net) { - struct nfs_net *nn = net_generic(net, nfs_net_id); - nfs_fs_proc_net_exit(net); - nfs_cleanup_cb_ident_idr(net); - WARN_ON_ONCE(!list_empty(&nn->nfs_client_list)); - WARN_ON_ONCE(!list_empty(&nn->nfs_volume_list)); + nfs_clients_exit(net); } static struct pernet_operations nfs_net_ops = { diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h index 498fab72f70b..9e87265907b8 100644 --- a/fs/nfs/internal.h +++ b/fs/nfs/internal.h @@ -158,6 +158,7 @@ extern void nfs_umount(const struct nfs_mount_request *info); /* client.c */ extern const struct rpc_program nfs_program; extern void nfs_clients_init(struct net *net); +extern void nfs_clients_exit(struct net *net); extern struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *); int nfs_create_rpc_client(struct nfs_client *, const struct nfs_client_initdata *, rpc_authflavor_t); struct nfs_client *nfs_get_client(const struct nfs_client_initdata *); @@ -170,7 +171,6 @@ int nfs_init_server_rpcclient(struct nfs_server *, const struct rpc_timeout *t, struct nfs_server *nfs_alloc_server(void); void nfs_server_copy_userdata(struct nfs_server *, struct nfs_server *); -extern void nfs_cleanup_cb_ident_idr(struct net *); extern void nfs_put_client(struct nfs_client *); extern void nfs_free_client(struct nfs_client *); extern struct nfs_client *nfs4_find_client_ident(struct net *, int); From patchwork Tue Jun 11 18:08:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10988111 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 6AB9014C0 for ; Tue, 11 Jun 2019 18:12:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5AA4128355 for ; Tue, 11 Jun 2019 18:12:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4EC0E2857E; Tue, 11 Jun 2019 18:12:07 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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 BF8662856F for ; Tue, 11 Jun 2019 18:12:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406851AbfFKSMG (ORCPT ); Tue, 11 Jun 2019 14:12:06 -0400 Received: from mail-io1-f66.google.com ([209.85.166.66]:35250 "EHLO mail-io1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406685AbfFKSMC (ORCPT ); Tue, 11 Jun 2019 14:12:02 -0400 Received: by mail-io1-f66.google.com with SMTP id m24so10722463ioo.2 for ; Tue, 11 Jun 2019 11:12:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=DWd/c8QEyTQVmbnPKbobpMg+XF2mkuTzRh+MjRTbsXo=; b=RHXLmA3e+3Hl/mh6qMdjIfj+fUoJTenxQscuXVeX6yhhMsURKDGxTLnxOwSxWAF6sf 6vfAC2EBHOKT8iAnRaXdokrTSHziYcVnR5fb7OZRbnV7ZJz/fzP76idcAHBR4jgoPXAu We0QiLKfQrPRX2mR0OMHela9xLt9eofwUAkaMMuO73Yt45OUeR1erbpsbq6f5qNkEOyJ ouJq9VDByNoF6NyLU6EMYXsUBlkrQf5P6n+ehCiDWDbYnjp+5w9SK9ASm+TRAR5eRA5A MdhyLuGw6GnpC39yzMfyQ5MOWFspC6baQW0WyBq+9thWJ4rbQ3NEQ+e2aYZlaFgNnQva IoQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DWd/c8QEyTQVmbnPKbobpMg+XF2mkuTzRh+MjRTbsXo=; b=J2X0Rw3yI9p4dinHvgVKcND7zwy8bYWZcoG/j8iJ6bxBEJLZKNrjcPlPtdS5eSV9FF 8e9IFZNr1klk+b2UHJN5Xk6Mm+BPT8YNi2IcUDwFCuLU027G4yzUAwwNA9NFM10pVWTM XsKYnSlrGluUoPu3MRKhsAeE+lt6HZRTjCd0DlaVRHZsBrdQwkWgTtEIuyfq/5cTWdW0 Io36SoTc6L1t1fBuC6dX2lKDmTNevOqBFgQT/8eDZS8NpSv90PDVl+NucQgcgWMLSl2q KknRQTvqDkr9u7UfXNnN5kMjSLTaOWVOuTKfmgTtcVQzvzhg//EixmGoBZVTS4R9spEW 72Gw== X-Gm-Message-State: APjAAAWtV1/pGqA7kaz1rIp9nNuyxm/Xw5JEZqyZfcqykXfr2sdM5Q1P zd7aViBzICREBUZMCdqZQNXz1X4= X-Google-Smtp-Source: APXvYqzGHWMAd3p6JMQ7eJLV7/NVm6wquOvV9moIidb6Ru4jUcwwgwPx5QyK0vaNPNGDA6BRmb7kSQ== X-Received: by 2002:a6b:c915:: with SMTP id z21mr44702871iof.182.1560276721607; Tue, 11 Jun 2019 11:12:01 -0700 (PDT) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id f4sm4900212iok.56.2019.06.11.11.12.00 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 11 Jun 2019 11:12:01 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: linux-nfs@vger.kernel.org Subject: [PATCH 3/3] NFS: Add sysfs support for per-container identifier Date: Tue, 11 Jun 2019 14:08:32 -0400 Message-Id: <20190611180832.119488-4-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190611180832.119488-3-trond.myklebust@hammerspace.com> References: <20190611180832.119488-1-trond.myklebust@hammerspace.com> <20190611180832.119488-2-trond.myklebust@hammerspace.com> <20190611180832.119488-3-trond.myklebust@hammerspace.com> MIME-Version: 1.0 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 In order to identify containers to the NFS client, we add a per-net sysfs attribute that udev can fill with the appropriate identifier. The identifier could be a unique hostname, but in most cases it will probably be a persisted uuid. Signed-off-by: Trond Myklebust --- fs/nfs/client.c | 4 ++ fs/nfs/netns.h | 3 ++ fs/nfs/sysfs.c | 118 ++++++++++++++++++++++++++++++++++++++++++++++++ fs/nfs/sysfs.h | 10 ++++ 4 files changed, 135 insertions(+) diff --git a/fs/nfs/client.c b/fs/nfs/client.c index 0acb104f7b00..6e7aeb543f6a 100644 --- a/fs/nfs/client.c +++ b/fs/nfs/client.c @@ -49,6 +49,7 @@ #include "pnfs.h" #include "nfs.h" #include "netns.h" +#include "sysfs.h" #define NFSDBG_FACILITY NFSDBG_CLIENT @@ -1072,12 +1073,15 @@ void nfs_clients_init(struct net *net) #endif spin_lock_init(&nn->nfs_client_lock); nn->boot_time = ktime_get_real(); + + nfs_netns_sysfs_setup(nn, net); } void nfs_clients_exit(struct net *net) { struct nfs_net *nn = net_generic(net, nfs_net_id); + nfs_netns_sysfs_destroy(nn); nfs_cleanup_cb_ident_idr(net); WARN_ON_ONCE(!list_empty(&nn->nfs_client_list)); WARN_ON_ONCE(!list_empty(&nn->nfs_volume_list)); diff --git a/fs/nfs/netns.h b/fs/nfs/netns.h index fc9978c58265..c8374f74dce1 100644 --- a/fs/nfs/netns.h +++ b/fs/nfs/netns.h @@ -15,6 +15,8 @@ struct bl_dev_msg { uint32_t major, minor; }; +struct nfs_netns_client; + struct nfs_net { struct cache_detail *nfs_dns_resolve; struct rpc_pipe *bl_device_pipe; @@ -29,6 +31,7 @@ struct nfs_net { unsigned short nfs_callback_tcpport6; int cb_users[NFS4_MAX_MINOR_VERSION + 1]; #endif + struct nfs_netns_client *nfs_client; spinlock_t nfs_client_lock; ktime_t boot_time; #ifdef CONFIG_PROC_FS diff --git a/fs/nfs/sysfs.c b/fs/nfs/sysfs.c index 7070711ff6c5..4f3390b20239 100644 --- a/fs/nfs/sysfs.c +++ b/fs/nfs/sysfs.c @@ -9,7 +9,12 @@ #include #include #include +#include +#include +#include +#include "nfs4_fs.h" +#include "netns.h" #include "sysfs.h" struct kobject *nfs_client_kobj; @@ -67,3 +72,116 @@ void nfs_sysfs_exit(void) kobject_put(nfs_client_kobj); kset_unregister(nfs_client_kset); } + +static ssize_t nfs_netns_identifier_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + struct nfs_netns_client *c = container_of(kobj, + struct nfs_netns_client, + kobject); + return scnprintf(buf, PAGE_SIZE, "%s\n", c->identifier); +} + +/* Strip trailing '\n' */ +static size_t nfs_string_strip(const char *c, size_t len) +{ + while (len > 0 && c[len-1] == '\n') + --len; + return len; +} + +static ssize_t nfs_netns_identifier_store(struct kobject *kobj, + struct kobj_attribute *attr, + const char *buf, size_t count) +{ + struct nfs_netns_client *c = container_of(kobj, + struct nfs_netns_client, + kobject); + const char *old; + char *p; + size_t len; + + len = nfs_string_strip(buf, min_t(size_t, count, CONTAINER_ID_MAXLEN)); + if (!len) + return 0; + p = kmemdup_nul(buf, len, GFP_KERNEL); + if (!p) + return -ENOMEM; + old = xchg(&c->identifier, p); + if (old) { + synchronize_rcu(); + kfree(old); + } + return count; +} + +static void nfs_netns_client_release(struct kobject *kobj) +{ + struct nfs_netns_client *c = container_of(kobj, + struct nfs_netns_client, + kobject); + + if (c->identifier) + kfree(c->identifier); + kfree(c); +} + +static const void *nfs_netns_client_namespace(struct kobject *kobj) +{ + return container_of(kobj, struct nfs_netns_client, kobject)->net; +} + +static struct kobj_attribute nfs_netns_client_id = __ATTR(identifier, + 0644, nfs_netns_identifier_show, nfs_netns_identifier_store); + +static struct attribute *nfs_netns_client_attrs[] = { + &nfs_netns_client_id.attr, + NULL, +}; + +static struct kobj_type nfs_netns_client_type = { + .release = nfs_netns_client_release, + .default_attrs = nfs_netns_client_attrs, + .sysfs_ops = &kobj_sysfs_ops, + .namespace = nfs_netns_client_namespace, +}; + +static struct nfs_netns_client *nfs_netns_client_alloc(struct kobject *parent, + struct net *net) +{ + struct nfs_netns_client *p; + + p = kzalloc(sizeof(*p), GFP_KERNEL); + if (p) { + p->net = net; + p->kobject.kset = nfs_client_kset; + if (kobject_init_and_add(&p->kobject, &nfs_netns_client_type, + parent, "nfs_client") == 0) + return p; + kobject_put(&p->kobject); + } + return NULL; +} + +void nfs_netns_sysfs_setup(struct nfs_net *netns, struct net *net) +{ + struct nfs_netns_client *clp; + + clp = nfs_netns_client_alloc(nfs_client_kobj, net); + if (clp) { + netns->nfs_client = clp; + kobject_uevent(&clp->kobject, KOBJ_ADD); + } +} + +void nfs_netns_sysfs_destroy(struct nfs_net *netns) +{ + struct nfs_netns_client *clp = netns->nfs_client; + + if (clp) { + kobject_uevent(&clp->kobject, KOBJ_REMOVE); + kobject_del(&clp->kobject); + kobject_put(&clp->kobject); + netns->nfs_client = NULL; + } +} diff --git a/fs/nfs/sysfs.h b/fs/nfs/sysfs.h index 666f8db2ba92..f1b27411dcc0 100644 --- a/fs/nfs/sysfs.h +++ b/fs/nfs/sysfs.h @@ -6,10 +6,20 @@ #ifndef __NFS_SYSFS_H #define __NFS_SYSFS_H +#define CONTAINER_ID_MAXLEN (64) + +struct nfs_netns_client { + struct kobject kobject; + struct net *net; + const char *identifier; +}; extern struct kobject *nfs_client_kobj; extern int nfs_sysfs_init(void); extern void nfs_sysfs_exit(void); +void nfs_netns_sysfs_setup(struct nfs_net *netns, struct net *net); +void nfs_netns_sysfs_destroy(struct nfs_net *netns); + #endif