[libvirt] stat() vs. access()

Hi! While discussing some code with Matthias, we stumbled across many occurances of stat() calls within the libVirt code (virFileExists() for example) which could be implemented in a cheaper way when using access() instead of stat(), when the only purpose is to check for the existance of a file. The one thing I'm concerned about, is the question if access() does the right thing in all situations. As the manpages didn't tell anything about directories it might be worth to clarify this in advance. A simple practical test showed that access ("/path/to/dir", F_OK) seems to work as expected. Any comments on these (optimization) thoughs? Ciao Matthias and Max -- Gib Dein Bestes. Dann übertriff Dich selbst!

On Sun, Nov 08, 2009 at 12:52:35AM +0100, Maximilian Wilhelm wrote:
Hi!
While discussing some code with Matthias, we stumbled across many occurances of stat() calls within the libVirt code (virFileExists() for example) which could be implemented in a cheaper way when using access() instead of stat(), when the only purpose is to check for the existance of a file.
The one thing I'm concerned about, is the question if access() does the right thing in all situations. As the manpages didn't tell anything about directories it might be worth to clarify this in advance.
A simple practical test showed that access ("/path/to/dir", F_OK) seems to work as expected.
Any comments on these (optimization) thoughs?
I don't see any problems with this idea, so if you want to do the conversion go for it. Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

Anno domini 2009 Daniel P. Berrange scripsit:
While discussing some code with Matthias, we stumbled across many occurances of stat() calls within the libVirt code (virFileExists() for example) which could be implemented in a cheaper way when using access() instead of stat(), when the only purpose is to check for the existance of a file.
The one thing I'm concerned about, is the question if access() does the right thing in all situations. As the manpages didn't tell anything about directories it might be worth to clarify this in advance.
A simple practical test showed that access ("/path/to/dir", F_OK) seems to work as expected.
Any comments on these (optimization) thoughs?
I don't see any problems with this idea, so if you want to do the conversion go for it.
Ok, I will have a look at this when I have a bit time these days. Ciao Max -- Lauf nicht vor Deinem Glück davon: Es könnte hinter Dir stehen!
participants (2)
-
Daniel P. Berrange
-
Maximilian Wilhelm