Received: by 10.223.185.111 with SMTP id b44csp1647345wrg; Sat, 10 Mar 2018 10:31:56 -0800 (PST) X-Google-Smtp-Source: AG47ELugRCn5pa5ri0LJ9yNbTil0v+y4HHV1Vd7Fo5mTZMOrWiZQAH2fI7HSVyWvMA88F6MysorX X-Received: by 10.98.57.215 with SMTP id u84mr2647031pfj.152.1520706716394; Sat, 10 Mar 2018 10:31:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520706716; cv=none; d=google.com; s=arc-20160816; b=CPLHgLSFbVqnegWvCXnqq3MegyPJI5qamu1mhTJ2aGYn/yUKnkftUnAVbG/Ydu3XCG jHkyJwAGJRMb8dM/9bWgdA70TN0LO28qSVDm3VYjK+lc8FuwbwN3nxlRZn9s9UawwOqa fe5hm0m/4MweVnXbRU+iFjP9YnHDigFSuxen0j43BqadhOkx4E8dGZrRDWFlMMyyY/f6 V3sYjyS+p0c15DLm6YQ+VzRTzCYwpBnsI+oqd8S0QtapC/meO4oum5jgFkeR7htI6qLc yCYmBQD3WTBLZUFbH1+nRVPbgL7ggDI1Z/yTvVb17BflaYABwCeWgpeL+SM5pEKHed9H cJyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=a92QQZxzKpjJPmK9b5e8ack3Hf0GQEl2D0hnjyo3RXQ=; b=OIYdZ2i60jP14YKfn8Ob6n64XKUUBS8gImD9NGjAx8VnejMk2oRnaXsC3skrK3ekgd 2E3CqWeo9GduP0v9yP/liEbZ6bb5LiNGtSRQEZc+76MMKupUx3pdOv8K+iOotRIgYW8X gGjzFy+A/31NtM0iTn2soWQCMpDD0GnJQScFByY2SFXyYSNTQkScS4t/wyWfyBs6JHRl nGf5gR5mRO6Xynl9N4QzkrJUC0oVl+obwg6jqOgF7B1/KYGPfcRgTUkebkl16GDjlHPZ +fBxmV1Sp00dLHY+EeMRA3ulGUjB2Xh2HtD4zxvCLRc2IF1VvE3SGR+LWvy/NwyGBjFJ TLxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@eng.ucsd.edu header.s=google header.b=UxzRYnGv; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k9-v6si3033091pll.300.2018.03.10.10.31.42; Sat, 10 Mar 2018 10:31:56 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@eng.ucsd.edu header.s=google header.b=UxzRYnGv; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751714AbeCJSa7 (ORCPT + 99 others); Sat, 10 Mar 2018 13:30:59 -0500 Received: from mail-pl0-f68.google.com ([209.85.160.68]:38912 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932693AbeCJSV0 (ORCPT ); Sat, 10 Mar 2018 13:21:26 -0500 Received: by mail-pl0-f68.google.com with SMTP id s13-v6so7023471plq.6 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=MkrsrH04GFKgNVuzO+Xs0jm0ppx3xIidu/7Bz79hlZuWW+Bi7fjvtmrgBVsO+0dvKC eRUaPfqnWS2wqMDErHLOC/U3RjN9szQ/yTUgiOglAmnMQxDO2un3l/qN0wyB/H3qBCOV aPIjhBn3ahCzAFnJMy9dd7SLRZyGZa4TfjWHxVah60/IoTKUsDRDJ9rV+bJgrDjRa0iw oTKPtLWVk94NIuA7Q8QptdXI2jlPnKHiur2RGt1PjRaMMduJfKhX0429HfH3i1fB83bH MMGWp2uYQ2FboUluZJQs8RdDAmjeX/NDwzCaCKxpO1aUvI2iEcg3gXt0XM4i9wyGZCUM rTZQ== X-Gm-Message-State: AElRT7FlNog+etlAqao39ORX/Li2XQmXXH3u7RgYQySaloB9ujSjWw+K 9f/VOeYZNRT4g46XT4ARLggWFUoaa7I= 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 Cc: dan.j.williams@intel.com, andy.rudoff@intel.com, coughlan@redhat.com, swanson@cs.ucsd.edu, david@fromorbit.com, jack@suse.com, swhiteho@redhat.com, miklos@szeredi.hu, andiry.xu@gmail.com, Andiry Xu 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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, }; -- 2.7.4