coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "ls -l": Avoid unnecessary getxattr() overhead


From: Bernhard Voelker
Subject: Re: "ls -l": Avoid unnecessary getxattr() overhead
Date: Fri, 17 Feb 2012 12:11:05 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.1) Gecko/20120208 Thunderbird/10.0.1

On 02/17/2012 11:35 AM, Jim Meyering wrote:
> Bernhard Voelker wrote:
>> Alternatively, it could write a certain line to stdout or stderr,
>> and for comparison, this pattern would have to be counted.

> Thanks for the patch.
> However, while I don't particularly like using fd 33, and might
> use stderr instead, I do want to avoid stdout.  With it, there seems
> to be too much risk that mixing wrapper-induced output with ls's normal
> output would cause trouble, e.g., if your __SPEEDUP__ token were not
> written right after a newline.
> 
> Instead, I've realized that I can eliminate the need for the wc post-
> processing by using the fact that our contrived output file is seekable:
> rather than simply writing to fd, first seek to position 0 each time,
> and write the count:
> 
> Here's a stand-alone test script.
> When it completes, the output file, "x"
> contains either nothing or a count of the number of calls.
> 
...
> Hmm... that means the case of no getxattr calls would still
> require a little special handling to map "empty file" to "0".
> With that, I still prefer the simpler, original write_1 function.

I agree.
We could maybe avoid the sed+mv by using a preprocessor define,
similar as I did in my previous patch:


diff --git a/tests/ls/getxattr-speedup b/tests/ls/getxattr-speedup
index f3dc5bb..58fd90a 100755
--- a/tests/ls/getxattr-speedup
+++ b/tests/ls/getxattr-speedup
@@ -32,19 +32,16 @@ cat > k.c <<'EOF' || framework_failure_
 static void
 write_1 (void)
 {
-  int fd = @FD@;
-  write (fd, "x\n", 2);
+  write (FD, "x\n", 2);
 }
 ssize_t getxattr (const char *path, const char *name, void *value, size_t size)
 { write_1 (); errno = ENOTSUP; return -1; }
 ssize_t lgetxattr(const char *path, const char *name, void *value, size_t size)
 { write_1 (); errno = ENOTSUP; return -1; }
 EOF
-sed "s/@FD@/$fd/" k.c > k || framework_failure_
-mv k k.c || framework_failure_

 # Then compile/link it:
-$CC -fPIC -O2 -c k.c || framework_failure_ 'failed to compile with -fPIC'
+$CC -DFD=$fd -fPIC -O2 -c k.c || framework_failure_ 'failed to compile with 
-fPIC'
 ld -G k.o -o k.so || framework_failure_ 'failed to invoke ld -G ...'

 # create a few files


BTW: I have another question: what if someone has used
"./configure --disable-xattr"? ... surprisingly nothing:
ls doesn't honor USE_XATTR. Is that correct?

Have a nice day,
Berny



reply via email to

[Prev in Thread] Current Thread [Next in Thread]