From patchwork Tue Aug 23 14:05:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 9295707 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 3FA3560574 for ; Tue, 23 Aug 2016 14:12:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 307F028AF9 for ; Tue, 23 Aug 2016 14:12:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 254DE28B23; Tue, 23 Aug 2016 14:12:24 +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=-6.9 required=2.0 tests=BAYES_00,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 786B528AF9 for ; Tue, 23 Aug 2016 14:12:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932592AbcHWOLw (ORCPT ); Tue, 23 Aug 2016 10:11:52 -0400 Received: from mail-wm0-f48.google.com ([74.125.82.48]:35519 "EHLO mail-wm0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755371AbcHWOLg (ORCPT ); Tue, 23 Aug 2016 10:11:36 -0400 Received: by mail-wm0-f48.google.com with SMTP id f65so164652508wmi.0 for ; Tue, 23 Aug 2016 07:11:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=jSYoZazJNrp86AdMBw617kePrgnm3Ub77zHit/oARfk=; b=CCDJ6uR9Ko6c71sFI4/flzPcR+s3TSAZ5nvQv92LtvFCAsi7yc0XZvg6N34ntYqOUu aCZqSw0R2qtVu4fmhXm7HJlqy3zUSyw/ChqGhOcQewI9WNAy6+qOVJJ09Yhb9jb/vGYm GirtvGA2inpy8o6AHxRbF0EUCIFp+gZm438KK2D9PmeLZWOstlMKA/xYXwJgNV2Jp5VF /4eOznwRYo6Z3OEGuJ4I7gnlbzNyPH0skdQS0BXksZAgOIJyOvlxw36k/9bmoP35BhPA VE0g0eKH2cn7bIMSnjn+nFAlSElUhZjZcDmc+0codFkqwj+zPVRF9BdtRz2sLennwj6R yK6w== X-Gm-Message-State: AEkoouu6KwHmTrFjnegq19Vnj2IwNadh5t3t6SyD0FbcU2SBOEZ7nhTuDsg2z3YNDWWJIets X-Received: by 10.28.220.8 with SMTP id t8mr21701193wmg.114.1471961140108; Tue, 23 Aug 2016 07:05:40 -0700 (PDT) Received: from veci.piliscsaba.szeredi.hu (pool-dsl-2c-0018.externet.hu. [217.173.44.24]) by smtp.gmail.com with ESMTPSA id wc3sm3993539wjc.47.2016.08.23.07.05.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Aug 2016 07:05:39 -0700 (PDT) From: Miklos Szeredi To: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Al Viro , Alexei Starovoitov , Greg Kroah-Hartman Subject: [PATCH 3/7] libfs: support RENAME_NOREPLACE in simple_rename() Date: Tue, 23 Aug 2016 16:05:28 +0200 Message-Id: <1471961132-1675-4-git-send-email-mszeredi@redhat.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1471961132-1675-1-git-send-email-mszeredi@redhat.com> References: <1471961132-1675-1-git-send-email-mszeredi@redhat.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 This is trivial to do: - add flags argument to simple_rename() - check if flags doesn't have any other than RENAME_NOREPLACE - assign simple_rename() to .rename2 instead of .rename Filesystems converted: hugetlbfs, ramfs, bpf. Debugfs uses simple_rename() to implement debugfs_rename(), which is for debugfs instances to rename files internally, not for userspace filesystem access. For this case pass zero flags to simple_rename(). Signed-off-by: Miklos Szeredi Cc: Alexei Starovoitov Cc: Greg Kroah-Hartman Acked-by: Greg Kroah-Hartman --- fs/debugfs/inode.c | 2 +- fs/hugetlbfs/inode.c | 2 +- fs/libfs.c | 6 +++++- fs/ramfs/inode.c | 2 +- include/linux/fs.h | 3 ++- kernel/bpf/inode.c | 2 +- 6 files changed, 11 insertions(+), 6 deletions(-) diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c index 72361baf9da7..5ac27c9de669 100644 --- a/fs/debugfs/inode.c +++ b/fs/debugfs/inode.c @@ -748,7 +748,7 @@ struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry, old_name = fsnotify_oldname_init(old_dentry->d_name.name); error = simple_rename(d_inode(old_dir), old_dentry, d_inode(new_dir), - dentry); + dentry, 0); if (error) { fsnotify_oldname_free(old_name); goto exit; diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index 4ea71eba40a5..50cd7475a942 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -988,7 +988,7 @@ static const struct inode_operations hugetlbfs_dir_inode_operations = { .mkdir = hugetlbfs_mkdir, .rmdir = simple_rmdir, .mknod = hugetlbfs_mknod, - .rename = simple_rename, + .rename2 = simple_rename, .setattr = hugetlbfs_setattr, }; diff --git a/fs/libfs.c b/fs/libfs.c index 74dc8b9e7f53..4758353b2d41 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -349,11 +349,15 @@ int simple_rmdir(struct inode *dir, struct dentry *dentry) EXPORT_SYMBOL(simple_rmdir); int simple_rename(struct inode *old_dir, struct dentry *old_dentry, - struct inode *new_dir, struct dentry *new_dentry) + struct inode *new_dir, struct dentry *new_dentry, + unsigned int flags) { struct inode *inode = d_inode(old_dentry); int they_are_dirs = d_is_dir(old_dentry); + if (flags & ~RENAME_NOREPLACE) + return -EINVAL; + if (!simple_empty(new_dentry)) return -ENOTEMPTY; diff --git a/fs/ramfs/inode.c b/fs/ramfs/inode.c index 1ab6e6c2e60e..c2aa068ff974 100644 --- a/fs/ramfs/inode.c +++ b/fs/ramfs/inode.c @@ -146,7 +146,7 @@ static const struct inode_operations ramfs_dir_inode_operations = { .mkdir = ramfs_mkdir, .rmdir = simple_rmdir, .mknod = ramfs_mknod, - .rename = simple_rename, + .rename2 = simple_rename, }; static const struct super_operations ramfs_ops = { diff --git a/include/linux/fs.h b/include/linux/fs.h index 3523bf62f328..8aebcfc42f26 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2949,7 +2949,8 @@ extern int simple_open(struct inode *inode, struct file *file); extern int simple_link(struct dentry *, struct inode *, struct dentry *); extern int simple_unlink(struct inode *, struct dentry *); extern int simple_rmdir(struct inode *, struct dentry *); -extern int simple_rename(struct inode *, struct dentry *, struct inode *, struct dentry *); +extern int simple_rename(struct inode *, struct dentry *, + struct inode *, struct dentry *, unsigned int); extern int noop_fsync(struct file *, loff_t, loff_t, int); extern int simple_empty(struct dentry *); extern int simple_readpage(struct file *file, struct page *page); diff --git a/kernel/bpf/inode.c b/kernel/bpf/inode.c index 5967b870a895..c92fd8936d33 100644 --- a/kernel/bpf/inode.c +++ b/kernel/bpf/inode.c @@ -189,7 +189,7 @@ static const struct inode_operations bpf_dir_iops = { .mknod = bpf_mkobj, .mkdir = bpf_mkdir, .rmdir = simple_rmdir, - .rename = simple_rename, + .rename2 = simple_rename, .link = simple_link, .unlink = simple_unlink, };