From patchwork Fri Sep 29 13:00:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 9978001 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 4797B60311 for ; Fri, 29 Sep 2017 13:00:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 36DB32988D for ; Fri, 29 Sep 2017 13:00:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2B97C2986C; Fri, 29 Sep 2017 13:00:48 +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 B9E5A29884 for ; Fri, 29 Sep 2017 13:00:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752448AbdI2NAq (ORCPT ); Fri, 29 Sep 2017 09:00:46 -0400 Received: from mx2.suse.de ([195.135.220.15]:42470 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752436AbdI2NAp (ORCPT ); Fri, 29 Sep 2017 09:00:45 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 5D25FACE5; Fri, 29 Sep 2017 13:00:44 +0000 (UTC) From: Goldwyn Rodrigues To: linux-xfs@vger.kernel.org Cc: darrick.wong@oracle.com, david@fromorbit.com, Goldwyn Rodrigues Subject: [PATCH v2 3/3] xfs_io: Allow partial writes Date: Fri, 29 Sep 2017 08:00:35 -0500 Message-Id: <20170929130035.24760-3-rgoldwyn@suse.de> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170929130035.24760-1-rgoldwyn@suse.de> References: <20170929130035.24760-1-rgoldwyn@suse.de> Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Goldwyn Rodrigues Partial writes are performed when there is an error midway while performing the I/O. Perform the write exactly once and return the number of bytes written so far, until the error. Signed-off-by: Goldwyn Rodrigues Reviewed-by: Brian Foster Reviewed-by: Darrick J. Wong --- io/io.h | 1 + io/pwrite.c | 25 ++++++++++++++++++++++++- man/man8/xfs_io.8 | 3 +++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/io/io.h b/io/io.h index 6a0fe657..3862985f 100644 --- a/io/io.h +++ b/io/io.h @@ -25,6 +25,7 @@ #define IO_RANDOM ( 0) #define IO_FORWARD ( 1) #define IO_BACKWARD (-1) +#define IO_ONCE ( 2) /* * File descriptor options diff --git a/io/pwrite.c b/io/pwrite.c index 2b85a528..dcf130d6 100644 --- a/io/pwrite.c +++ b/io/pwrite.c @@ -47,6 +47,7 @@ pwrite_help(void) " -W -- call fsync(2) at the end (included in timing results)\n" " -B -- write backwards through the range from offset (backwards N bytes)\n" " -F -- write forwards through the range of bytes from offset (default)\n" +" -O -- perform pwrite call once and return (maybe partial) bytes written\n" " -R -- write at random offsets in the specified range of bytes\n" " -Z N -- zeed the random number generator (used when writing randomly)\n" " (heh, zorry, the -s/-S arguments were already in use in pwrite)\n" @@ -258,6 +259,22 @@ write_buffer( return ops; } +static int +write_once( + off64_t offset, + long long count, + long long *total, + int pwritev2_flags) +{ + size_t bytes; + bytes = do_pwrite(file->fd, offset, count, count, pwritev2_flags); + if (bytes < 0) + return -1; + *total = bytes; + return 1; +} + + static int pwrite_f( int argc, @@ -279,7 +296,7 @@ pwrite_f( init_cvtnum(&fsblocksize, &fssectsize); bsize = fsblocksize; - while ((c = getopt(argc, argv, "b:BCdf:Fi:NqRs:S:uV:wWZ:")) != EOF) { + while ((c = getopt(argc, argv, "b:BCdf:Fi:NqRs:OS:uV:wWZ:")) != EOF) { switch (c) { case 'b': tmp = cvtnum(fsblocksize, fssectsize, optarg); @@ -301,6 +318,9 @@ pwrite_f( case 'R': direction = IO_RANDOM; break; + case 'O': + direction = IO_ONCE; + break; case 'd': dflag = 1; break; @@ -392,6 +412,9 @@ pwrite_f( case IO_BACKWARD: c = write_backward(offset, &count, &total, pwritev2_flags); break; + case IO_ONCE: + c = write_once(offset, count, &total, pwritev2_flags); + break; default: total = 0; ASSERT(0); diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8 index 9c58914f..b7c0f099 100644 --- a/man/man8/xfs_io.8 +++ b/man/man8/xfs_io.8 @@ -263,6 +263,9 @@ write the buffers in a reserve sequential direction. .B \-R write the buffers in the give range in a random order. .TP +.B \-O +perform pwrite once and return the (maybe partial) bytes written. +.TP .B \-Z seed specify the random number seed used for random write .TP