From patchwork Fri Oct 28 15:52:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Vrabel X-Patchwork-Id: 9402197 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 DE7016022E for ; Fri, 28 Oct 2016 15:55:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D10A12A86A for ; Fri, 28 Oct 2016 15:55:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C5D032A86E; Fri, 28 Oct 2016 15:55: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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7B03B2A86A for ; Fri, 28 Oct 2016 15:55:07 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c09Sf-0005FP-VA; Fri, 28 Oct 2016 15:52:53 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c09Se-0005Eo-Cn for xen-devel@lists.xenproject.org; Fri, 28 Oct 2016 15:52:52 +0000 Received: from [193.109.254.147] by server-11.bemta-6.messagelabs.com id 29/EE-14466-45473185; Fri, 28 Oct 2016 15:52:52 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprAIsWRWlGSWpSXmKPExsXitHRDpG5wiXC EQcM3VYvvWyYzOTB6HP5whSWAMYo1My8pvyKBNePuui9sBe+EK94eW8PcwHhcoIuRk0NCwF/i x5Kf7CA2m4COxOMlM8BsESD7d8NZli5GLg5mgQeMEk9+vWIESQgLuEv8uPqcFcRmEVCVuLVqD pjNK+AmMXH2bCaIoXIS54//ZAaxOYHqd756BNYrBFRz78VvVghbReLj2lVQvYISJ2c+YQGxmQ UkJA6+eAHUywE0h1vib7f9BEa+WUiqZiGpWsDItIpRvTi1qCy1SNdML6koMz2jJDcxM0fX0MB MLze1uDgxPTUnMalYLzk/dxMjMKQYgGAH47wT/ocYJTmYlER5P4QLRwjxJeWnVGYkFmfEF5Xm pBYfYpTh4FCS4L1VBJQTLEpNT61Iy8wBBjdMWoKDR0mEN6IYKM1bXJCYW5yZDpE6xagoJc77F KRPACSRUZoH1waLqEuMslLCvIxAhwjxFKQW5WaWoMq/YhTnYFQS5lUCGc+TmVcCN/0V0GImoM XT0wVAFpckIqSkGhgFHmz8HHqe37AlJ5yhVGauns8hyR6T993ZT/6cf+l/M5QpIjjk1xWL4Pl OudGnDrJPSl12araKXfKqRS2zC5IXzdU+U+hbc/hcs+9c082q72q7VsYdPuCjEiS2vsY+auK6 KJ2TUWZC4iwRK85HLPvJuYlpxhHpCXbHXOIqJz0+YGX4slr552wlluKMREMt5qLiRAABk0AWo wIAAA== X-Env-Sender: prvs=102855286=david.vrabel@citrix.com X-Msg-Ref: server-12.tower-27.messagelabs.com!1477669969!68002189!2 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.0.13; banners=-,-,- X-VirusChecked: Checked Received: (qmail 45681 invoked from network); 28 Oct 2016 15:52:51 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-12.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 28 Oct 2016 15:52:51 -0000 X-IronPort-AV: E=Sophos;i="5.31,410,1473120000"; d="scan'208";a="386656935" From: David Vrabel To: Alexander Viro Date: Fri, 28 Oct 2016 16:52:37 +0100 Message-ID: <1477669959-9486-2-git-send-email-david.vrabel@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1477669959-9486-1-git-send-email-david.vrabel@citrix.com> References: <1477669959-9486-1-git-send-email-david.vrabel@citrix.com> MIME-Version: 1.0 X-DLP: MIA1 Cc: Juergen Gross , linux-kernel@vger.kernel.org, David Vrabel , linux-fsdevel@vger.kernel.org, xen-devel@lists.xenproject.org, Boris Ostrovsky Subject: [Xen-devel] [PATCHv4 1/3] libfs: allow simple_fill_super() to add symlinks X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP simple_fill_super() will add symlinks if an entry has mode & S_IFLNK. The target is provided in the new "link" field. Signed-off-by: David Vrabel --- v4: - Use switch for file type. v2: - simplified. --- fs/libfs.c | 27 ++++++++++++++++++++++++--- include/linux/fs.h | 2 +- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/fs/libfs.c b/fs/libfs.c index 48826d4..8eabcb1 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -509,6 +509,7 @@ int simple_fill_super(struct super_block *s, unsigned long magic, struct dentry *root; struct dentry *dentry; int i; + int ret = -ENOMEM; s->s_blocksize = PAGE_SIZE; s->s_blocksize_bits = PAGE_SHIFT; @@ -550,9 +551,29 @@ int simple_fill_super(struct super_block *s, unsigned long magic, dput(dentry); goto out; } - inode->i_mode = S_IFREG | files->mode; + switch (files->mode & S_IFMT) { + case S_IFLNK: + inode->i_mode = files->mode; + inode->i_op = &simple_symlink_inode_operations; + inode->i_link = kstrdup(files->link, GFP_KERNEL); + if (!inode->i_link) { + iput(inode); + dput(dentry); + goto out; + } + break; + case S_IFREG: + case 0: + inode->i_mode = S_IFREG | files->mode; + inode->i_fop = files->ops; + break; + default: + iput(inode); + dput(dentry); + ret = -EINVAL; + goto out; + } inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode); - inode->i_fop = files->ops; inode->i_ino = i; d_add(dentry, inode); } @@ -562,7 +583,7 @@ int simple_fill_super(struct super_block *s, unsigned long magic, d_genocide(root); shrink_dcache_parent(root); dput(root); - return -ENOMEM; + return ret; } EXPORT_SYMBOL(simple_fill_super); diff --git a/include/linux/fs.h b/include/linux/fs.h index 16d2b6e..4b64fbb 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2988,7 +2988,7 @@ extern const struct file_operations simple_dir_operations; extern const struct inode_operations simple_dir_inode_operations; extern void make_empty_dir_inode(struct inode *inode); extern bool is_empty_dir_inode(struct inode *inode); -struct tree_descr { char *name; const struct file_operations *ops; int mode; }; +struct tree_descr { char *name; const struct file_operations *ops; int mode; char *link; }; struct dentry *d_alloc_name(struct dentry *, const char *); extern int simple_fill_super(struct super_block *, unsigned long, struct tree_descr *); extern int simple_pin_fs(struct file_system_type *, struct vfsmount **mount, int *count);