From patchwork Tue Jan 14 12:53:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Yang X-Patchwork-Id: 1222768 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-108659-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=cn.fujitsu.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha1 header.s=default header.b=ZmGzjJaY; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47xr8z6bxNz9sP6 for ; Tue, 14 Jan 2020 23:57:55 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding:content-type; q=dns; s= default; b=PRcKyo0lgD2e2C8xdP5q0YhhqAtr2d3xeXF8cuoam21VwUPt5ZqRn gzsmihe6CTcADe4S7JjWEqV9eTt/8NrwJVbmRhAS/vPjFTqgvAUjBXhoHRv+Vhsp w0me7QOCdtILMScjG6PWbtKhY4PBkZw57iNMxA+/CFQaktcgC5KF+Q= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding:content-type; s=default; bh=utvbeYHVFhAyj2E87v1s5CviOkQ=; b=ZmGzjJaYqTe7h3CQkcexFcY4StL1 ddFZRahmjIbTh44UIImoOUeUdrSv2KZJNcQFxvkXSKGPRO6vf8qbYC4ILtpsxvYT MHeZ1109B0XnekMR+6yrqVvPvdQ8H8oJi2Jv0GjUfNha/Wf1M+wggrriUG4lGWDK +HogUANCeMZgqVI= Received: (qmail 1053 invoked by alias); 14 Jan 2020 12:57:49 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 1045 invoked by uid 89); 14 Jan 2020 12:57:49 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy=HX-Languages-Length:2015, racy, HContent-Transfer-Encoding:8bit X-HELO: heian.cn.fujitsu.com From: Xiao Yang To: CC: Xiao Yang Subject: [PATCH] sysdeps/posix/posix_fallocate*: Make emulated posix_fallocate() work properly Date: Tue, 14 Jan 2020 20:53:14 +0800 Message-ID: <20200114125314.19093-1-yangx.jy@cn.fujitsu.com> MIME-Version: 1.0 X-yoursite-MailScanner-ID: BAA394CE1CB3.AAEF4 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: yangx.jy@cn.fujitsu.com Emulated posix_fallocate() only writes data in one block if block size is 4096, offset is 4095 and len is 2. The emulated code should write data in two blocks in the case because it actually crosses two blocks. Signed-off-by: Xiao Yang --- sysdeps/posix/posix_fallocate.c | 14 ++++++++++++++ sysdeps/posix/posix_fallocate64.c | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/sysdeps/posix/posix_fallocate.c b/sysdeps/posix/posix_fallocate.c index e7fccfc1c8..f661124c0f 100644 --- a/sysdeps/posix/posix_fallocate.c +++ b/sysdeps/posix/posix_fallocate.c @@ -93,6 +93,20 @@ posix_fallocate (int fd, __off_t offset, __off_t len) increment = 4096; } + if (offset % increment + len % increment > increment) + { + if (offset < st.st_size) + { + unsigned char b; + ssize_t rdsize = __pread (fd, &b, 1, offset); + if (rdsize < 0) + return errno; + } else { + if (__pwrite (fd, "", 1, offset) != 1) + return errno; + } + } + /* Write a null byte to every block. This is racy; we currently lack a better option. Compare-and-swap against a file mapping might additional local races, but requires interposition of a diff --git a/sysdeps/posix/posix_fallocate64.c b/sysdeps/posix/posix_fallocate64.c index f9d4fe5ca3..2d75ce2786 100644 --- a/sysdeps/posix/posix_fallocate64.c +++ b/sysdeps/posix/posix_fallocate64.c @@ -93,6 +93,20 @@ __posix_fallocate64_l64 (int fd, __off64_t offset, __off64_t len) increment = 4096; } + if (offset % increment + len % increment > increment) + { + if (offset < st.st_size) + { + unsigned char b; + ssize_t rdsize = __pread (fd, &b, 1, offset); + if (rdsize < 0) + return errno; + } else { + if (__pwrite (fd, "", 1, offset) != 1) + return errno; + } + } + /* Write a null byte to every block. This is racy; we currently lack a better option. Compare-and-swap against a file mapping might address local races, but requires interposition of a signal