From patchwork Thu May 14 17:35:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Eric W. Biederman" X-Patchwork-Id: 6408841 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 1F914C0433 for ; Thu, 14 May 2015 17:40:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 315F52027D for ; Thu, 14 May 2015 17:40:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 220A220489 for ; Thu, 14 May 2015 17:40:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1422750AbbENRj4 (ORCPT ); Thu, 14 May 2015 13:39:56 -0400 Received: from out03.mta.xmission.com ([166.70.13.233]:42610 "EHLO out03.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1422728AbbENRjv (ORCPT ); Thu, 14 May 2015 13:39:51 -0400 Received: from in02.mta.xmission.com ([166.70.13.52]) by out03.mta.xmission.com with esmtps (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1Ysx6s-0006Id-0s; Thu, 14 May 2015 11:39:50 -0600 Received: from 67-3-205-90.omah.qwest.net ([67.3.205.90] helo=x220.int.ebiederm.org.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1Ysx6r-0004XR-55; Thu, 14 May 2015 11:39:49 -0600 From: ebiederm@xmission.com (Eric W. Biederman) To: Linux Containers Cc: , Linux API , "Serge E. Hallyn" , Andy Lutomirski , Richard Weinberger , Kenton Varda , Michael Kerrisk-manpages , =?utf-8?Q?St=C3=A9phane?= Graber , Eric Windisch , Greg Kroah-Hartman , Tejun Heo References: <87pp63jcca.fsf@x220.int.ebiederm.org> Date: Thu, 14 May 2015 12:35:02 -0500 In-Reply-To: <87pp63jcca.fsf@x220.int.ebiederm.org> (Eric W. Biederman's message of "Thu, 14 May 2015 12:30:45 -0500") Message-ID: <87fv6zhxkp.fsf@x220.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 X-XM-AID: U2FsdGVkX1/iRUO79KgvbQkSfQFNfoAa55t4DUFpntQ= X-SA-Exim-Connect-IP: 67.3.205.90 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-DCC: XMission; sa05 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ***;Linux Containers X-Spam-Relay-Country: X-Spam-Timing: total 252 ms - load_scoreonly_sql: 0.03 (0.0%), signal_user_changed: 2.9 (1.1%), b_tie_ro: 2.1 (0.8%), parse: 0.70 (0.3%), extract_message_metadata: 10 (4.0%), get_uri_detail_list: 1.51 (0.6%), tests_pri_-1000: 4.9 (1.9%), tests_pri_-950: 1.05 (0.4%), tests_pri_-900: 0.86 (0.3%), tests_pri_-400: 21 (8.3%), check_bayes: 20 (7.9%), b_tokenize: 6 (2.5%), b_tok_get_all: 6 (2.3%), b_comp_prob: 1.54 (0.6%), b_tok_touch_all: 3.1 (1.2%), b_finish: 0.68 (0.3%), tests_pri_0: 205 (81.3%), tests_pri_500: 3.5 (1.4%), rewrite_mail: 0.00 (0.0%) Subject: [CFT][PATCH 08/10] sysfs: Add support for permanently empty directories. X-SA-Exim-Version: 4.2.1 (built Wed, 24 Sep 2014 11:00:52 -0600) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add two functions sysfs_create_empty_dir and sysfs_remove_empty_dir that hang a permanently empty directory off of a kobject or remove a permanently emptpy directory hanging from a kobject. Export these new functions so modular filesystems can use them. As all permanently empty directories are, are names and used for mouting other filesystems this seems like the right abstraction. Cc: stable@vger.kernel.org Signed-off-by: "Eric W. Biederman" --- fs/sysfs/dir.c | 34 ++++++++++++++++++++++++++++++++++ include/linux/sysfs.h | 16 ++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c index 0b45ff42f374..8244741474d7 100644 --- a/fs/sysfs/dir.c +++ b/fs/sysfs/dir.c @@ -121,3 +121,37 @@ int sysfs_move_dir_ns(struct kobject *kobj, struct kobject *new_parent_kobj, return kernfs_rename_ns(kn, new_parent, kn->name, new_ns); } + +/** + * sysfs_create_empty_dir - create an always empty directory + * @parent_kobj: kobject that will contain this always empty directory + * @name: The name of the always empty directory to add + */ +int sysfs_create_empty_dir(struct kobject *parent_kobj, const char *name) +{ + struct kernfs_node *kn, *parent = parent_kobj->sd; + + kn = kernfs_create_empty_dir(parent, name, NULL); + if (IS_ERR(kn)) { + if (PTR_ERR(kn) == -EEXIST) + sysfs_warn_dup(parent, name); + return PTR_ERR(kn); + } + + return 0; +} +EXPORT_SYMBOL_GPL(sysfs_create_empty_dir); + +/** + * sysfs_remove_empty_dir - remove an always empty directory. + * @parent_kobj: kobject that will contain this always empty directory + * @name: The name of the always empty directory to remove + * + */ +void sysfs_remove_empty_dir(struct kobject *parent_kobj, const char *name) +{ + struct kernfs_node *parent = parent_kobj->sd; + + kernfs_remove_by_name_ns(parent, name, NULL); +} +EXPORT_SYMBOL_GPL(sysfs_remove_empty_dir); diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index 99382c0df17e..e156d419de75 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -210,6 +210,10 @@ int __must_check sysfs_rename_dir_ns(struct kobject *kobj, const char *new_name, int __must_check sysfs_move_dir_ns(struct kobject *kobj, struct kobject *new_parent_kobj, const void *new_ns); +int __must_check sysfs_create_empty_dir(struct kobject *parent_kobj, + const char *name); +void sysfs_remove_empty_dir(struct kobject *parent_kobj, + const char *name); int __must_check sysfs_create_file_ns(struct kobject *kobj, const struct attribute *attr, @@ -298,6 +302,18 @@ static inline int sysfs_move_dir_ns(struct kobject *kobj, return 0; } +static inline int sysfs_create_empty_dir(struct kobject *parent_kobj, + const char *name) +{ + return 0; +} + +static inline void sysfs_remove_empty_dir(struct kobject *parent_kobj, + const char *name) +{ + return 0; +} + static inline int sysfs_create_file_ns(struct kobject *kobj, const struct attribute *attr, const void *ns)