From patchwork Mon Sep 8 22:17:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernhard Reutner-Fischer X-Patchwork-Id: 387059 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from whitealder.osuosl.org (whitealder.osuosl.org [140.211.166.138]) by ozlabs.org (Postfix) with ESMTP id 4E8AE140086 for ; Tue, 9 Sep 2014 08:17:22 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 3B78A8BE0A; Mon, 8 Sep 2014 22:17:21 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id tU-dO7hTym7r; Mon, 8 Sep 2014 22:17:19 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by whitealder.osuosl.org (Postfix) with ESMTP id 878348BF0B; Mon, 8 Sep 2014 22:17:19 +0000 (UTC) X-Original-To: uclibc@lists.busybox.net Delivered-To: uclibc@osuosl.org Received: from hemlock.osuosl.org (hemlock.osuosl.org [140.211.166.133]) by ash.osuosl.org (Postfix) with ESMTP id AEA611BFA75 for ; Mon, 8 Sep 2014 22:17:18 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id AC56393155 for ; Mon, 8 Sep 2014 22:17:18 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Y8lDUYfOQxqv for ; Mon, 8 Sep 2014 22:17:17 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com [209.85.217.182]) by hemlock.osuosl.org (Postfix) with ESMTPS id 5993F93135 for ; Mon, 8 Sep 2014 22:17:17 +0000 (UTC) Received: by mail-lb0-f182.google.com with SMTP id v6so1789106lbi.41 for ; Mon, 08 Sep 2014 15:17:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=zoXMviBfjHHgGvNIiICK42Ep0jWyLIkKVjQEqpSZm00=; b=rDLcH34NrfaifntDEmWPQLRljtqk+JhfuwwllitTp5gGx1Q43CI4mf/EnGdnye/6mQ icS7TKbRUWij7y3RexQE7016y2AZmXlXw7BAY/UCt5WxmtTV8OpBCiUVc85G+BKb6kyb tTlTA/oW5GXaInAV9c9rf0U9Ecvdd3kIcCsVcQ8JTYWWuAMLBslqRaaefVcOp5SPC0Xa erN8sB+CrqXt//V/ZxjtylJIm4M3/FzkMyWVwAr8b5Z8PFSqDC6At0YX/5Ato8NbSMwK bBgCOQiF9VNANue6V/kAwT/9AVIaGJzpS+PWriTB8V/PV7CH5YlBWK1tPz5b/DVP6OVc Y/nA== X-Received: by 10.112.202.106 with SMTP id kh10mr30323645lbc.66.1410214635454; Mon, 08 Sep 2014 15:17:15 -0700 (PDT) Received: from nbbrfq.cc.univie.ac.at (91-119-140-39.dynamic.xdsl-line.inode.at. [91.119.140.39]) by mx.google.com with ESMTPSA id m1sm3916111lbc.49.2014.09.08.15.17.12 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Sep 2014 15:17:12 -0700 (PDT) Date: Tue, 9 Sep 2014 00:17:10 +0200 From: Bernhard Reutner-Fischer To: basile@opensource.dyc.edu Subject: Re: [PATCH] libc: add fallocate() and fallocate64() Message-ID: <20140908221710.GA8663@nbbrfq.cc.univie.ac.at> References: <1410118426-20163-1-git-send-email-basile@opensource.dyc.edu> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1410118426-20163-1-git-send-email-basile@opensource.dyc.edu> User-Agent: Mutt/1.5.23 (2014-03-12) Cc: blueness@gentoo.org, uclibc@uclibc.org X-BeenThere: uclibc@uclibc.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Discussion and development of uClibc \(the embedded C library\)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: uclibc-bounces@uclibc.org Sender: uclibc-bounces@uclibc.org On Sun, Sep 07, 2014 at 03:33:46PM -0400, basile@opensource.dyc.edu wrote: > From: "Anthony G. Basile" > > We add the Linux-specific function fallocate() which allows the user to > directly manipulate allocate space for a file. fallocate() can operate > in different modes, but the default mode is equivalent to posix_fallocate() > which is specified in POSIX.1. > > Recent releases of e2fsprogs 1.42.11 and above expect fallocate64() to be > available. Looks good. A few remarks: $ egrep "(ADVANCED_R|LINUX_SPEC|LFS)" .config UCLIBC_HAS_LFS=y UCLIBC_LINUX_SPECIFIC=y UCLIBC_HAS_ADVANCED_REALTIME=y libc/sysdeps/linux/common/fallocate.c:17:22: warning: no previous prototype for '_fallocate' [-Wmissing-prototypes] int attribute_hidden _fallocate(int fd, int mode, __off_t offset, __off_t len) ----------------------^ libc/sysdeps/linux/common/fallocate64.c:22:22: warning: no previous prototype for '_fallocate64' [-Wmissing-prototypes] int attribute_hidden _fallocate64(int fd, int mode, __off64_t offset, __off64_t len) ----------------------^ text data bss dec hex filename 86 0 0 86 56 posix_fallocate.os 102 0 0 102 66 posix_fallocate64.os 142 0 0 142 8e fallocate.os 143 0 0 143 8f fallocate64.os Attached incremental patch: text data bss dec hex filename 86 0 0 86 56 posix_fallocate.os 102 0 0 102 66 posix_fallocate64.os 117 0 0 117 75 fallocate.os 118 0 0 118 76 fallocate64.os We should drop the libc_hidden_proto(fallocate{,64}) since we do not have internal users (and iff we gain some they should use __libc_fallocate{,64}) though. I did not test 32bit vs 64bit targets nor all combos of the egrep above. Care to test and send an updated patch, please? TIA, diff --git a/include/fcntl.h b/include/fcntl.h index eb72ce4..a312ca1 100644 --- a/include/fcntl.h +++ b/include/fcntl.h @@ -245,8 +245,9 @@ extern int posix_fallocate64 (int __fd, __off64_t __offset, __off64_t __len); Unlike the latter, fallocate can operate in different modes. The default mode = 0 is equivalent to posix_fallocate(). - Note: These declarations are used in posix_fallocate.c and posix_fallocate64.c, - so we expose them internally. */ + Note: These declarations are used in posix_fallocate.c and + posix_fallocate64.c, so we expose them internally. + */ /* Flags for fallocate's mode. */ # define FALLOC_FL_KEEP_SIZE 1 /* Don't extend size of file @@ -256,6 +257,7 @@ extern int posix_fallocate64 (int __fd, __off64_t __offset, __off64_t __len); # ifndef __USE_FILE_OFFSET64 extern int fallocate (int __fd, int __mode, __off_t __offset, __off_t __len); +libc_hidden_proto(fallocate) # else # ifdef __REDIRECT extern int __REDIRECT (fallocate, (int __fd, int __mode, __off64_t __offset, @@ -267,6 +269,7 @@ extern int __REDIRECT (fallocate, (int __fd, int __mode, __off64_t __offset, # endif # ifdef __USE_LARGEFILE64 extern int fallocate64 (int __fd, int __mode, __off64_t __offset, __off64_t __len); +libc_hidden_proto(fallocate64) # endif #endif diff --git a/libc/sysdeps/linux/common/Makefile.in b/libc/sysdeps/linux/common/Makefile.in index 98a7af2..8562154 100644 --- a/libc/sysdeps/linux/common/Makefile.in +++ b/libc/sysdeps/linux/common/Makefile.in @@ -62,17 +62,10 @@ CSRC-$(UCLIBC_LINUX_SPECIFIC) += \ vmsplice.c CSRC-$(if $(findstring yy,$(UCLIBC_LINUX_SPECIFIC)$(UCLIBC_HAS_LFS)),y) += \ sendfile64.c -# posix_fallocate() needs the internal function _fallocate() defined in fallocate.c -# and posix_fallocate64() needs _fallocate64() in fallocate64.c if LFS is enabled. -# So we do not remove them even if we want just posix_fallocate() or posix_fallocate64(). -ifeq ($(findstring y,$(UCLIBC_LINUX_SPECIFIC)$(UCLIBC_HAS_ADVANCED_REALTIME)),y) -ifneq ($(findstring y,$(UCLIBC_HAS_LFS)),y) -CSRC- += fallocate64.c -endif -else -CSRC- += fallocate.c -CSRC- += fallocate64.c -endif +# posix_fallocate() needs __libc_fallocate() from fallocate.c +# posix_fallocate64() needs __libc_fallocate64() from fallocate64.c +CSRC-$(if $(UCLIBC_LINUX_SPECIFIC)$(UCLIBC_HAS_ADVANCED_REALTIME),y,) += \ + fallocate.c $(filter fallocate64.c,$(CSRC-y)) # NPTL needs these internally: madvise.c CSRC-$(findstring y,$(UCLIBC_LINUX_SPECIFIC)$(UCLIBC_HAS_THREADS_NATIVE)) += madvise.c ifeq ($(UCLIBC_HAS_THREADS_NATIVE),y) diff --git a/libc/sysdeps/linux/common/fallocate.c b/libc/sysdeps/linux/common/fallocate.c index c16cd17..3a43f93 100644 --- a/libc/sysdeps/linux/common/fallocate.c +++ b/libc/sysdeps/linux/common/fallocate.c @@ -14,7 +14,8 @@ #include #if defined __NR_fallocate -int attribute_hidden _fallocate(int fd, int mode, __off_t offset, __off_t len) +extern __typeof(fallocate) __libc_fallocate attribute_hidden; +int attribute_hidden __libc_fallocate(int fd, int mode, __off_t offset, __off_t len) { int ret; @@ -39,13 +40,11 @@ int attribute_hidden _fallocate(int fd, int mode, __off_t offset, __off_t len) } # if defined __UCLIBC_LINUX_SPECIFIC__ && defined __USE_GNU -int fallocate(int fd, int mode, __off_t offset, __off_t len) -{ - return _fallocate(fd, mode, offset, len); -} -# if defined __UCLIBC_HAS_LFS__ && __WORDSIZE == 64 -strong_alias(fallocate,fallocate64) +strong_alias(__libc_fallocate,fallocate) +libc_hidden_def(fallocate) +# if __WORDSIZE == 64 +strong_alias(__libc_fallocate,fallocate64) +libc_hidden_def(fallocate64) # endif # endif - #endif diff --git a/libc/sysdeps/linux/common/fallocate64.c b/libc/sysdeps/linux/common/fallocate64.c index e81c69a..8bacc79 100644 --- a/libc/sysdeps/linux/common/fallocate64.c +++ b/libc/sysdeps/linux/common/fallocate64.c @@ -19,7 +19,9 @@ # if __WORDSIZE == 64 /* Can use normal fallocate() */ # elif __WORDSIZE == 32 -int attribute_hidden _fallocate64(int fd, int mode, __off64_t offset, __off64_t len) +extern __typeof(fallocate64) __libc_fallocate64 attribute_hidden; +int attribute_hidden __libc_fallocate64(int fd, int mode, __off64_t offset, + __off64_t len) { int ret; INTERNAL_SYSCALL_DECL(err); @@ -31,10 +33,8 @@ int attribute_hidden _fallocate64(int fd, int mode, __off64_t offset, __off64_t } # if defined __UCLIBC_LINUX_SPECIFIC__ && defined __USE_GNU -int fallocate64(int fd, int mode, __off64_t offset, __off64_t len) -{ - return _fallocate64(fd, mode, offset, len); -} +strong_alias(__libc_fallocate64,fallocate64) +libc_hidden_def(fallocate64) # endif # else diff --git a/libc/sysdeps/linux/common/posix_fallocate.c b/libc/sysdeps/linux/common/posix_fallocate.c index 9e9b09c..76771e3 100644 --- a/libc/sysdeps/linux/common/posix_fallocate.c +++ b/libc/sysdeps/linux/common/posix_fallocate.c @@ -13,12 +13,11 @@ #include #include -extern __typeof(fallocate) _fallocate attribute_hidden; - #if defined __NR_fallocate +extern __typeof(fallocate) __libc_fallocate attribute_hidden; int posix_fallocate(int fd, __off_t offset, __off_t len) { - return _fallocate(fd, 0, offset, len); + return __libc_fallocate(fd, 0, offset, len); } # if defined __UCLIBC_HAS_LFS__ && __WORDSIZE == 64 strong_alias(posix_fallocate,posix_fallocate64) diff --git a/libc/sysdeps/linux/common/posix_fallocate64.c b/libc/sysdeps/linux/common/posix_fallocate64.c index d5875ca..12ddbc2 100644 --- a/libc/sysdeps/linux/common/posix_fallocate64.c +++ b/libc/sysdeps/linux/common/posix_fallocate64.c @@ -13,17 +13,16 @@ #include #include -extern __typeof(fallocate64) _fallocate64 attribute_hidden; - #if defined __NR_fallocate # if __WORDSIZE == 64 /* Can use normal posix_fallocate() */ # elif __WORDSIZE == 32 +extern __typeof(fallocate64) __libc_fallocate64 attribute_hidden; int posix_fallocate64(int fd, __off64_t offset, __off64_t len) { - return _fallocate64(fd, 0, offset, len); + return __libc_fallocate64(fd, 0, offset, len); } # else -# error your machine is neither 32 bit or 64 bit ... it must be magical +# error your machine is neither 32 bit or 64 bit ... it must be magical # endif #endif diff --git a/test/unistd/Makefile.in b/test/unistd/Makefile.in index 0aaefb5..ed33d9a 100644 --- a/test/unistd/Makefile.in +++ b/test/unistd/Makefile.in @@ -6,21 +6,15 @@ ifeq ($(UCLIBC_HAS_LFS),) TESTS_DISABLED := tst-preadwrite64 tst-posix_fallocate64 tst-fallocate64 endif -# If we don't have LINUX_SPECIFIC, then get rid of tst-fallocate, and check to -# make sure we didn't miss removing tst-fallocate64 above because LFS is enabled +# If we don't have LINUX_SPECIFIC, then get rid of tst-fallocate ifeq ($(UCLIBC_LINUX_SPECIFIC),) TESTS_DISABLED += tst-fallocate -ifeq ($(UCLIBC_HAS_LFS),y) -TESTS_DISABLED += tst-fallocate64 -endif endif -# The logic is similar for HAS_ADVANCED_REALTIME and tst-posix_fallocate/tst-posix_fallocate64 +# The logic is similar for HAS_ADVANCED_REALTIME and +# tst-posix_fallocate/tst-posix_fallocate64 ifeq ($(UCLIBC_HAS_ADVANCED_REALTIME),) TESTS_DISABLED += tst-posix_fallocate -ifeq ($(UCLIBC_HAS_LFS),y) -TESTS_DISABLED += tst-posix_fallocate64 -endif endif OPTS_getopt := -abcXXX -9 diff --git a/test/unistd/tst-fallocate.c b/test/unistd/tst-fallocate.c index 2b15596..0f61821 100644 --- a/test/unistd/tst-fallocate.c +++ b/test/unistd/tst-fallocate.c @@ -10,12 +10,6 @@ # endif #endif -static void do_prepare (void); -#define PREPARE(argc, argv) do_prepare () -static int do_test (void); -#define TEST_FUNCTION do_test () -#include - static int fd; static void do_prepare (void) @@ -161,3 +155,7 @@ do_test (void) return 0; } + +#define PREPARE(argc, argv) do_prepare () +#define TEST_FUNCTION do_test () +#include