From patchwork Sat Mar 10 18:18:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andiry Xu X-Patchwork-Id: 10273959 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 4310E605F3 for ; Sat, 10 Mar 2018 18:21:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 31ACF28BAE for ; Sat, 10 Mar 2018 18:21:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2622B29759; Sat, 10 Mar 2018 18:21:44 +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 AE7C2296E5 for ; Sat, 10 Mar 2018 18:21:43 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 021612264630B; Sat, 10 Mar 2018 10:15:17 -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:c00::241; helo=mail-pf0-x241.google.com; envelope-from=jix024@eng.ucsd.edu; receiver=linux-nvdimm@lists.01.org Received: from mail-pf0-x241.google.com (mail-pf0-x241.google.com [IPv6:2607:f8b0:400e:c00::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 EF470226462FD for ; Sat, 10 Mar 2018 10:15:14 -0800 (PST) Received: by mail-pf0-x241.google.com with SMTP id 68so2620092pfx.3 for ; Sat, 10 Mar 2018 10:21:33 -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=aHhVoo/2mwYBUNkfDWI29mhPXaLgSbjbR5jOhMq3j98=; b=SuVl52grORQW/8KG//qPQlGlbg0ChhHM+yBRdzJXjYvfbVTZ2IohBBkwvx6tdl7qAX lQQU5kQQzhwShODX5G3oaAVMqRl991Ynmd5FktiJmv532EiuRIiLSK54Q+pe2SHvSydM dKxTU91DIjcorV/DQlj7AVEHR76rCOXLOMj+M= 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=aHhVoo/2mwYBUNkfDWI29mhPXaLgSbjbR5jOhMq3j98=; b=R6LG5huE1rDifjjuIVonUlWrzntVAT2ZHUAke7l6DosdGxwwVcFowcx6FksaMkNB0Z bN/3Vd57L1aNbOfONR6dCsKH7CRuMoj2Wy3rydW6QsCLVwVTIxuuGx3rqk9NDJkvAAIZ zDmPuseNPbVQXvA79EqKffZEs7Y8rfkDou12w7TEbL5RjqursuoZBvYz+dtixjG3oEww 2HiKX/Eiez6H1eMk/dtAOX1oTU2coHKJhN3b4X7BqNqmfZLUSCnsWMyE52vaqSTIyYKv YMg5ZO6yMbUwS7q6uxKsCTNnCAwtDJ4ZhHaqO/u/ePMP8z/L8eur3iid+5f4NWLJh5eS uA7g== X-Gm-Message-State: AElRT7Ep6xkkpfbMoXEVIoTyM6dkWmm52HP0SIqBclwcGcu/FfBhmS5Y 7sHOZx3RlkQy+f3PeyYWHm+1WA== X-Google-Smtp-Source: AG47ELtcI2AM8Tm9DTSVz6NHVfW0huIwTQpCiTfU90iFv74GG8P5PZZWBR6oCWkRtOpVF+YTzb67Dw== X-Received: by 10.99.60.72 with SMTP id i8mr2165127pgn.399.1520706093453; Sat, 10 Mar 2018 10:21:33 -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.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 10 Mar 2018 10:21:32 -0800 (PST) From: Andiry Xu To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvdimm@lists.01.org Subject: [RFC v2 64/83] File operation: open, fsync, flush. Date: Sat, 10 Mar 2018 10:18:45 -0800 Message-Id: <1520705944-6723-65-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 persists file metadata and data before returning to the user space. Hence, fsync is a no-op if the file is not mmaped. Signed-off-by: Andiry Xu --- fs/nova/file.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/fs/nova/file.c b/fs/nova/file.c index ecaf20a..f60fdf3 100644 --- a/fs/nova/file.c +++ b/fs/nova/file.c @@ -66,9 +66,59 @@ static loff_t nova_llseek(struct file *file, loff_t offset, int origin) return offset; } +/* This function is called by both msync() and fsync(). + * TODO: Check if we can avoid calling nova_flush_buffer() for fsync. We use + * movnti to write data to files, so we may want to avoid doing unnecessary + * nova_flush_buffer() on fsync() + */ +static int nova_fsync(struct file *file, loff_t start, loff_t end, int datasync) +{ + struct address_space *mapping = file->f_mapping; + unsigned long start_pgoff, end_pgoff; + int ret = 0; + timing_t fsync_time; + + NOVA_START_TIMING(fsync_t, fsync_time); + + if (datasync) + NOVA_STATS_ADD(fdatasync, 1); + + /* No need to flush if the file is not mmaped */ + if (!mapping_mapped(mapping)) + goto persist; + + start_pgoff = start >> PAGE_SHIFT; + end_pgoff = (end + 1) >> PAGE_SHIFT; + nova_dbgv("%s: msync pgoff range %lu to %lu\n", + __func__, start_pgoff, end_pgoff); + + ret = generic_file_fsync(file, start, end, datasync); + +persist: + PERSISTENT_BARRIER(); + NOVA_END_TIMING(fsync_t, fsync_time); + + return ret; +} + +/* This callback is called when a file is closed */ +static int nova_flush(struct file *file, fl_owner_t id) +{ + PERSISTENT_BARRIER(); + return 0; +} + +static int nova_open(struct inode *inode, struct file *filp) +{ + return generic_file_open(inode, filp); +} + const struct file_operations nova_dax_file_operations = { .llseek = nova_llseek, + .open = nova_open, + .fsync = nova_fsync, + .flush = nova_flush, }; const struct inode_operations nova_file_inode_operations = {