From patchwork Sat Mar 10 18:18:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andiry Xu X-Patchwork-Id: 10273923 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 B7C0A602BD for ; Sat, 10 Mar 2018 18:21:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A755428BAE for ; Sat, 10 Mar 2018 18:21:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9B8DF29735; Sat, 10 Mar 2018 18:21: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=-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 4443428BAE for ; Sat, 10 Mar 2018 18:21:24 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id A46202263148C; Sat, 10 Mar 2018 10:14:59 -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:c05::243; helo=mail-pg0-x243.google.com; envelope-from=jix024@eng.ucsd.edu; receiver=linux-nvdimm@lists.01.org Received: from mail-pg0-x243.google.com (mail-pg0-x243.google.com [IPv6:2607:f8b0:400e:c05::243]) (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 C863E22631484 for ; Sat, 10 Mar 2018 10:14:56 -0800 (PST) Received: by mail-pg0-x243.google.com with SMTP id a15so484614pgn.5 for ; Sat, 10 Mar 2018 10:21:15 -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=R7Klix0uIBptd6q1kpVQLdMiOXEbKi6rdTJRBEL1NiQ=; b=hTf7lqrLOR1dPdj1EveBWn7io00Dw8IZw0AmiGWhCOtgJrJtKYM8Aiaf7otueY79sc 0LwlZnCVT4iAwEIIlCBKg69Co+DpRLrov6YWictCwJMH25p+NRzTWH+EujYkNqdCFo7k UahrA5fJMGGhGUuRLCimAcQArCDdBcu8lpbz0= 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=R7Klix0uIBptd6q1kpVQLdMiOXEbKi6rdTJRBEL1NiQ=; b=lg6wzf3fYiozjrNNOniC9gWEb43q1BfGPHc0/VVUCNEwgtzjxKLyfoj0sw0X4TNB22 EIp3KdGj3s/sOat0HNlDtbbfs9DiFYINSCiiRer/EL3yZZzwx1rIOR5GotQ8zFdFqhOO 0O3Mz7jMmlnno/0rc7wX0POmxNfSonTCMLT67RZyb12giY3W0WbDTd+1mPOA+t0GaVji 8772XPKB1mYn3z/svUYCKWxyq47MzZjLdRlwQU/I15SWLowxYGqnw6WMRefhuiRrUrlz oqLaCtaQO++6Q+p2aSen8Bk2cHMODiwlcgEl78gYJ+lp980p7V9a0kTCeeHD4YevEeYJ s+Jg== X-Gm-Message-State: AElRT7E2gr28Ag8AqWSeQ+bo/DYg4mLoLg5FIzYVsYxpya9ULf11YLur go47rQ2TcHS2qhpWWMOvTKRtyw== X-Google-Smtp-Source: AG47ELszmkyEefESXpPbmk23pmrcLWl48NtqsHhgcB6SZPyeyq3RZImZ+ush1FmHGTT/nMlPM73vYg== X-Received: by 10.98.157.199 with SMTP id a68mr2659818pfk.59.1520706075236; Sat, 10 Mar 2018 10:21:15 -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.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 10 Mar 2018 10:21:14 -0800 (PST) From: Andiry Xu To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvdimm@lists.01.org Subject: [RFC v2 49/83] Dir: Append create/remove dentry. Date: Sat, 10 Mar 2018 10:18:30 -0800 Message-Id: <1520705944-6723-50-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 NOVA adds or removes a directory/file by appending a dentry to the parent directory's log. Dentry contains filename and inode number. A positive inode number indicates a create(valid) dentry, and a dentry with inode number zero is a remove dentry. NOVA can also inplace update a create dentry to invalidate it. Signed-off-by: Andiry Xu --- fs/nova/dir.c | 140 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/nova/nova.h | 4 ++ 2 files changed, 144 insertions(+) diff --git a/fs/nova/dir.c b/fs/nova/dir.c index 35a66f9..47ee9ad 100644 --- a/fs/nova/dir.c +++ b/fs/nova/dir.c @@ -222,6 +222,146 @@ int nova_append_dir_init_entries(struct super_block *sb, return 0; } +/* adds a directory entry pointing to the inode. assumes the inode has + * already been logged for consistency + */ +int nova_add_dentry(struct dentry *dentry, u64 ino, int inc_link, + struct nova_inode_update *update, u64 epoch_id) +{ + struct inode *dir = dentry->d_parent->d_inode; + struct super_block *sb = dir->i_sb; + struct nova_inode_info *si = NOVA_I(dir); + struct nova_inode_info_header *sih = &si->header; + struct nova_inode *pidir; + const char *name = dentry->d_name.name; + int namelen = dentry->d_name.len; + struct nova_dentry *direntry; + unsigned short loglen; + int ret; + u64 curr_entry; + timing_t add_dentry_time; + + nova_dbg_verbose("%s: dir %lu new inode %llu\n", + __func__, dir->i_ino, ino); + nova_dbg_verbose("%s: %s %d\n", __func__, name, namelen); + NOVA_START_TIMING(add_dentry_t, add_dentry_time); + if (namelen == 0) + return -EINVAL; + + pidir = nova_get_inode(sb, dir); + + /* + * XXX shouldn't update any times until successful + * completion of syscall, but too many callers depend + * on this. + */ + dir->i_mtime = dir->i_ctime = current_time(dir); + + loglen = NOVA_DIR_LOG_REC_LEN(namelen); + ret = nova_append_dentry(sb, pidir, dir, dentry, + ino, loglen, update, + inc_link, epoch_id); + + if (ret) { + nova_dbg("%s: append dir entry failure\n", __func__); + return ret; + } + + curr_entry = update->curr_entry; + direntry = (struct nova_dentry *)nova_get_block(sb, curr_entry); + sih->last_dentry = curr_entry; + ret = nova_insert_dir_radix_tree(sb, sih, name, namelen, direntry); + + sih->trans_id++; + NOVA_END_TIMING(add_dentry_t, add_dentry_time); + return ret; +} + +static int nova_can_inplace_update_dentry(struct super_block *sb, + struct nova_dentry *dentry, u64 epoch_id) +{ + if (dentry && dentry->epoch_id == epoch_id) + return 1; + + return 0; +} + +/* removes a directory entry pointing to the inode. assumes the inode has + * already been logged for consistency + */ +int nova_remove_dentry(struct dentry *dentry, int dec_link, + struct nova_inode_update *update, u64 epoch_id) +{ + struct inode *dir = dentry->d_parent->d_inode; + struct super_block *sb = dir->i_sb; + struct nova_sb_info *sbi = NOVA_SB(sb); + struct nova_inode_info *si = NOVA_I(dir); + struct nova_inode_info_header *sih = &si->header; + struct nova_inode *pidir; + struct qstr *entry = &dentry->d_name; + struct nova_dentry *old_dentry = NULL; + unsigned short loglen; + int ret; + u64 curr_entry; + timing_t remove_dentry_time; + + NOVA_START_TIMING(remove_dentry_t, remove_dentry_time); + + update->create_dentry = NULL; + update->delete_dentry = NULL; + + if (!dentry->d_name.len) { + ret = -EINVAL; + goto out; + } + + ret = nova_remove_dir_radix_tree(sb, sih, entry->name, entry->len, 0, + &old_dentry); + + if (ret) + goto out; + + pidir = nova_get_inode(sb, dir); + + dir->i_mtime = dir->i_ctime = current_time(dir); + + if (nova_can_inplace_update_dentry(sb, old_dentry, epoch_id)) { + nova_inplace_update_dentry(sb, dir, old_dentry, + dec_link, epoch_id); + curr_entry = nova_get_addr_off(sbi, old_dentry); + + sih->last_dentry = curr_entry; + /* Leave create/delete_dentry to NULL + * Do not change tail if used as input + */ + if (update->tail == 0) { + update->tail = sih->log_tail; + } + sih->trans_id++; + goto out; + } + + loglen = NOVA_DIR_LOG_REC_LEN(entry->len); + ret = nova_append_dentry(sb, pidir, dir, dentry, + 0, loglen, update, + dec_link, epoch_id); + + if (ret) { + nova_dbg("%s: append dir entry failure\n", __func__); + goto out; + } + + update->create_dentry = old_dentry; + curr_entry = update->curr_entry; + update->delete_dentry = (struct nova_dentry *)nova_get_block(sb, + curr_entry); + sih->last_dentry = curr_entry; + sih->trans_id++; +out: + NOVA_END_TIMING(remove_dentry_t, remove_dentry_time); + return ret; +} + static u64 nova_find_next_dentry_addr(struct super_block *sb, struct nova_inode_info_header *sih, u64 pos) { diff --git a/fs/nova/nova.h b/fs/nova/nova.h index ed269fe..3a51dae 100644 --- a/fs/nova/nova.h +++ b/fs/nova/nova.h @@ -461,6 +461,10 @@ struct nova_dentry *nova_find_dentry(struct super_block *sb, unsigned long name_len); int nova_append_dir_init_entries(struct super_block *sb, struct nova_inode *pi, u64 self_ino, u64 parent_ino, u64 epoch_id); +int nova_add_dentry(struct dentry *dentry, u64 ino, int inc_link, + struct nova_inode_update *update, u64 epoch_id); +int nova_remove_dentry(struct dentry *dentry, int dec_link, + struct nova_inode_update *update, u64 epoch_id); /* rebuild.c */ int nova_rebuild_inode(struct super_block *sb, struct nova_inode_info *si,