1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-03 05:18:29 +03:00

Introduce is_same_inode macro, now including a comparison of st_dev.

* lib/misc/lvm-file.h (is_same_inode): Define.
* lib/filters/filter-persistent.c (persistent_filter_dump): Use is_same_inode
in place of a direct st_ino-only comparison.
* lib/locking/file_locking.c (_release_lock, _lock_file): Likewise.
This commit is contained in:
Jim Meyering 2007-07-20 15:22:46 +00:00
parent 57015b12e2
commit c93e6b5f79
4 changed files with 8 additions and 4 deletions

View File

@ -1,5 +1,5 @@
Version 2.02.28 - Version 2.02.28 -
================================ Introduce is_same_inode macro, now including a comparison of st_dev.
Don't leak a file descriptor in _lock_file(), when flock fails. Don't leak a file descriptor in _lock_file(), when flock fails.
Add SUN's LDOM virtual block device to filters Add SUN's LDOM virtual block device to filters
Split metadata-external.h out from metadata.h for the tools to use. Split metadata-external.h out from metadata.h for the tools to use.

View File

@ -208,7 +208,7 @@ int persistent_filter_dump(struct dev_filter *f)
goto out; goto out;
} }
if (!memcmp(&info.st_ino, &info2.st_ino, sizeof(ino_t))) if (is_same_inode(info, info2))
break; break;
fcntl_unlock_file(lockfd); fcntl_unlock_file(lockfd);

View File

@ -64,7 +64,7 @@ static int _release_lock(const char *file, int unlock)
if (!flock(ll->lf, LOCK_NB | LOCK_EX) && if (!flock(ll->lf, LOCK_NB | LOCK_EX) &&
!stat(ll->res, &buf1) && !stat(ll->res, &buf1) &&
!fstat(ll->lf, &buf2) && !fstat(ll->lf, &buf2) &&
!memcmp(&buf1.st_ino, &buf2.st_ino, sizeof(ino_t))) is_same_inode(buf1, buf2))
if (unlink(ll->res)) if (unlink(ll->res))
log_sys_error("unlink", ll->res); log_sys_error("unlink", ll->res);
@ -190,7 +190,7 @@ static int _lock_file(const char *file, int flags)
} }
if (!stat(ll->res, &buf1) && !fstat(ll->lf, &buf2) && if (!stat(ll->res, &buf1) && !fstat(ll->lf, &buf2) &&
!memcmp(&buf1.st_ino, &buf2.st_ino, sizeof(ino_t))) is_same_inode(buf1, buf2))
break; break;
} while (!(flags & LCK_NONBLOCK)); } while (!(flags & LCK_NONBLOCK));

View File

@ -52,4 +52,8 @@ void sync_dir(const char *file);
int fcntl_lock_file(const char *file, short lock_type, int warn_if_read_only); int fcntl_lock_file(const char *file, short lock_type, int warn_if_read_only);
void fcntl_unlock_file(int lockfd); void fcntl_unlock_file(int lockfd);
#define is_same_inode(buf1, buf2) \
((buf1).st_ino == (buf2).st_ino && \
(buf1).st_dev == (buf2).st_dev)
#endif #endif