From patchwork Sat Mar 10 18:18:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andiry Xu X-Patchwork-Id: 10273941 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 75676605D2 for ; Sat, 10 Mar 2018 18:21:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 651E328BAE for ; Sat, 10 Mar 2018 18:21:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 59A2F29735; Sat, 10 Mar 2018 18:21:34 +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=-1.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_NONE,T_DKIM_INVALID autolearn=no version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 103E628BAE for ; Sat, 10 Mar 2018 18:21:34 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 75C5B22603AFA; Sat, 10 Mar 2018 10:15:08 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:400e:c01::241; helo=mail-pl0-x241.google.com; envelope-from=jix024@eng.ucsd.edu; receiver=linux-nvdimm@lists.01.org Received: from mail-pl0-x241.google.com (mail-pl0-x241.google.com [IPv6:2607:f8b0:400e:c01::241]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 719512263149D for ; Sat, 10 Mar 2018 10:15:06 -0800 (PST) Received: by mail-pl0-x241.google.com with SMTP id w12-v6so7031041plp.4 for ; Sat, 10 Mar 2018 10:21:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eng.ucsd.edu; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=a92QQZxzKpjJPmK9b5e8ack3Hf0GQEl2D0hnjyo3RXQ=; b=UxzRYnGvd81i5a3A10TYjVfqhyKbXYFK3zzEK48KcLlA5lWZCXp1VowDJYuwBM52HM w4KugkZiLWbeKdQLpq9Zlc2+7gayCyPi9CQ24R/g3ULqHfxMGuM+SMAIX8b+OUNa6eGx +YL3VeZFViFxgtkhcj87+NPORMLbLi6yIcy9w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=a92QQZxzKpjJPmK9b5e8ack3Hf0GQEl2D0hnjyo3RXQ=; b=rCva+bLVyPS6okXHapffTrgRV5JFgMNjlicjDKxU5I4C9MiQ8nHY5rhbqZka6xaUMK 7yMN/tjzQY6aho6N78R+h1taOVm4wjHDMfgsYeXrXRVveOoV07O+0LzVL4g1oPjG7eHG nZx0L+eljDGwqlGRJumo81LLvH5XHCQ2s9vBbPWrQG8gbJwczGiAH4Wr9C3MjfTCnCqr mMfoJe4gQUgsvuyDEq5nmuYQs4FmLATyeUfHN9aflIebdyt1/fRt0Fh9MrnckkGSh2DG tNxgtSboD2URuKP59v7fFQkrLO59al/2exi8J3jtQy2l0pxjF0zHPqY5JsHCS6f1RL5Y VISg== X-Gm-Message-State: AElRT7EKX9a4mxL2yxTow5ABpfleoSkLVCLlkhOxC/JesFQeylva6oog rWz9K+jk8zcrUqGkaTG2YIerlA== X-Google-Smtp-Source: AG47ELuzVn4ONLxWGJZ2UJ9Ci+Klkz5ea9RRYeEaaJAKfO6ZCllnEmM0GCfcFxSDFkG2QiF9zpPQAg== X-Received: by 2002:a17:902:47c2:: with SMTP id d2-v6mr2746372plh.253.1520706084895; Sat, 10 Mar 2018 10:21:24 -0800 (PST) Received: from brienza-desktop.8.8.4.4 (andxu.ucsd.edu. [132.239.17.134]) by smtp.gmail.com with ESMTPSA id h80sm9210167pfj.181.2018.03.10.10.21.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 10 Mar 2018 10:21:24 -0800 (PST) From: Andiry Xu To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvdimm@lists.01.org Subject: [RFC v2 57/83] Namei: rmdir Date: Sat, 10 Mar 2018 10:18:38 -0800 Message-Id: <1520705944-6723-58-git-send-email-jix024@eng.ucsd.edu> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1520705944-6723-1-git-send-email-jix024@eng.ucsd.edu> References: <1520705944-6723-1-git-send-email-jix024@eng.ucsd.edu> X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: coughlan@redhat.com, miklos@szeredi.hu, Andiry Xu , david@fromorbit.com, jack@suse.com, swanson@cs.ucsd.edu, swhiteho@redhat.com, andiry.xu@gmail.com MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP From: Andiry Xu Similar to unlink. Signed-off-by: Andiry Xu --- fs/nova/namei.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) diff --git a/fs/nova/namei.c b/fs/nova/namei.c index 360d716..4bf6396 100644 --- a/fs/nova/namei.c +++ b/fs/nova/namei.c @@ -437,6 +437,110 @@ static int nova_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) goto out; } +/* + * routine to check that the specified directory is empty (for rmdir) + */ +static int nova_empty_dir(struct inode *inode) +{ + struct super_block *sb; + struct nova_inode_info *si = NOVA_I(inode); + struct nova_inode_info_header *sih = &si->header; + struct nova_dentry *entry; + unsigned long pos = 0; + struct nova_dentry *entries[4]; + int nr_entries; + int i; + + sb = inode->i_sb; + nr_entries = radix_tree_gang_lookup(&sih->tree, + (void **)entries, pos, 4); + if (nr_entries > 2) + return 0; + + for (i = 0; i < nr_entries; i++) { + entry = entries[i]; + + if (!is_dir_init_entry(sb, entry)) + return 0; + } + + return 1; +} + +static int nova_rmdir(struct inode *dir, struct dentry *dentry) +{ + struct inode *inode = dentry->d_inode; + struct nova_dentry *de; + struct super_block *sb = inode->i_sb; + struct nova_inode *pi = nova_get_inode(sb, inode), *pidir; + struct nova_inode_update update_dir; + struct nova_inode_update update; + u64 old_linkc = 0; + struct nova_inode_info *si = NOVA_I(inode); + struct nova_inode_info_header *sih = &si->header; + int err = -ENOTEMPTY; + u64 epoch_id; + timing_t rmdir_time; + + NOVA_START_TIMING(rmdir_t, rmdir_time); + if (!inode) + return -ENOENT; + + nova_dbgv("%s: name %s\n", __func__, dentry->d_name.name); + pidir = nova_get_inode(sb, dir); + if (!pidir) + return -EINVAL; + + if (nova_inode_by_name(dir, &dentry->d_name, &de) == 0) + return -ENOENT; + + if (!nova_empty_dir(inode)) + return err; + + nova_dbgv("%s: inode %lu, dir %lu, link %d\n", __func__, + inode->i_ino, dir->i_ino, dir->i_nlink); + + if (inode->i_nlink != 2) + nova_dbg("empty directory %lu has nlink!=2 (%d), dir %lu", + inode->i_ino, inode->i_nlink, dir->i_ino); + + epoch_id = nova_get_epoch_id(sb); + + update_dir.tail = 0; + err = nova_remove_dentry(dentry, -1, &update_dir, epoch_id); + if (err) + goto end_rmdir; + + /*inode->i_version++; */ + clear_nlink(inode); + inode->i_ctime = dir->i_ctime; + + if (dir->i_nlink) + drop_nlink(dir); + + nova_delete_dir_tree(sb, sih); + + update.tail = 0; + err = nova_append_link_change_entry(sb, pi, inode, &update, + &old_linkc, epoch_id); + if (err) + goto end_rmdir; + + nova_lite_transaction_for_time_and_link(sb, pi, pidir, inode, dir, + &update, &update_dir, 1, epoch_id); + + nova_invalidate_link_change_entry(sb, old_linkc); + nova_invalidate_dentries(sb, &update_dir); + + NOVA_END_TIMING(rmdir_t, rmdir_time); + return err; + +end_rmdir: + nova_err(sb, "%s return %d\n", __func__, err); + NOVA_END_TIMING(rmdir_t, rmdir_time); + return err; +} + struct dentry *nova_get_parent(struct dentry *child) { struct inode *inode; @@ -467,5 +571,6 @@ const struct inode_operations nova_dir_inode_operations = { .link = nova_link, .unlink = nova_unlink, .mkdir = nova_mkdir, + .rmdir = nova_rmdir, .mknod = nova_mknod, };