* [PATCH] e4defrag: Handle device symlinks
@ 2012-07-19 19:02 Eric Sandeen
2012-07-19 19:04 ` Eric Sandeen
2012-07-28 21:54 ` Theodore Ts'o
0 siblings, 2 replies; 3+ messages in thread
From: Eric Sandeen @ 2012-07-19 19:02 UTC (permalink / raw)
To: ext4 development; +Cc: Kazuya Mio
Device nodes are commonly accessed via symlinks, i.e.
# ls -l /dev/mapper/testvg-testlv
lrwxrwxrwx. 1 root root 7 Jul 19 13:01 /dev/mapper/testvg-testlv -> ../dm-0
Today, e4defrag on such a device will fail:
# e4defrag -c /dev/mapper/testvg-testlv
File is not regular file
"/dev/mapper/testvg-testlv"
due to it being a link, and e4defrag on the link target does as well:
# e4defrag -c /dev/dm-0
Filesystem is not mounted
due to the target not being found in /etc/mtab.
Fix this by checking whether the symlink target is a block device
and if so, using that device in main(), and also changing get_mount_point()
to search for a matching device number, not device name.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---
diff --git a/misc/e4defrag.c b/misc/e4defrag.c
index 6491edd..260265c 100644
--- a/misc/e4defrag.c
+++ b/misc/e4defrag.c
@@ -266,8 +266,15 @@ static int get_mount_point(const char *devname, char *mount_point,
{
/* Refer to /etc/mtab */
const char *mtab = MOUNTED;
- FILE *fp = NULL;
+ FILE *fp = NULL;
struct mntent *mnt = NULL;
+ struct stat64 sb;
+
+ if (stat64(devname, &sb) < 0) {
+ perror(NGMSG_FILE_INFO);
+ PRINT_FILE_NAME(devname);
+ return -1;
+ }
fp = setmntent(mtab, "r");
if (fp == NULL) {
@@ -276,7 +283,15 @@ static int get_mount_point(const char *devname, char *mount_point,
}
while ((mnt = getmntent(fp)) != NULL) {
- if (strcmp(devname, mnt->mnt_fsname) != 0)
+ struct stat64 ms;
+
+ /*
+ * To handle device symlinks, we see if the
+ * device number matches, not the name
+ */
+ if (stat64(mnt->mnt_fsname, &ms) < 0)
+ continue;
+ if (sb.st_rdev != ms.st_rdev)
continue;
endmntent(fp);
@@ -1770,6 +1785,15 @@ int main(int argc, char *argv[])
continue;
}
+ /* Handle i.e. lvm device symlinks */
+ if (S_ISLNK(buf.st_mode)) {
+ struct stat64 buf2;
+
+ if (stat64(argv[i], &buf2) == 0 &&
+ S_ISBLK(buf2.st_mode))
+ buf = buf2;
+ }
+
if (S_ISBLK(buf.st_mode)) {
/* Block device */
strncpy(dev_name, argv[i], strnlen(argv[i], PATH_MAX));
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] e4defrag: Handle device symlinks
2012-07-19 19:02 [PATCH] e4defrag: Handle device symlinks Eric Sandeen
@ 2012-07-19 19:04 ` Eric Sandeen
2012-07-28 21:54 ` Theodore Ts'o
1 sibling, 0 replies; 3+ messages in thread
From: Eric Sandeen @ 2012-07-19 19:04 UTC (permalink / raw)
To: ext4 development; +Cc: Kazuya Mio, xake
On 7/19/12 2:02 PM, Eric Sandeen wrote:
> Device nodes are commonly accessed via symlinks, i.e.
>
> # ls -l /dev/mapper/testvg-testlv
> lrwxrwxrwx. 1 root root 7 Jul 19 13:01 /dev/mapper/testvg-testlv -> ../dm-0
>
> Today, e4defrag on such a device will fail:
FWIW this addresses Red Hat Bugzilla #707209
and was
Reported-by: Peter Hjalmarsson <xake@rymdraket.net>
-Eric
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] e4defrag: Handle device symlinks
2012-07-19 19:02 [PATCH] e4defrag: Handle device symlinks Eric Sandeen
2012-07-19 19:04 ` Eric Sandeen
@ 2012-07-28 21:54 ` Theodore Ts'o
1 sibling, 0 replies; 3+ messages in thread
From: Theodore Ts'o @ 2012-07-28 21:54 UTC (permalink / raw)
To: Eric Sandeen; +Cc: ext4 development, Kazuya Mio
On Thu, Jul 19, 2012 at 02:02:30PM -0500, Eric Sandeen wrote:
> Device nodes are commonly accessed via symlinks, i.e.
>
> # ls -l /dev/mapper/testvg-testlv
> lrwxrwxrwx. 1 root root 7 Jul 19 13:01 /dev/mapper/testvg-testlv -> ../dm-0
>
> Today, e4defrag on such a device will fail:
>
> # e4defrag -c /dev/mapper/testvg-testlv
> File is not regular file
> "/dev/mapper/testvg-testlv"
>
> due to it being a link, and e4defrag on the link target does as well:
>
> # e4defrag -c /dev/dm-0
> Filesystem is not mounted
>
> due to the target not being found in /etc/mtab.
>
> Fix this by checking whether the symlink target is a block device
> and if so, using that device in main(), and also changing get_mount_point()
> to search for a matching device number, not device name.
>
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Thanks, applied.
- Ted
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-07-28 21:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-19 19:02 [PATCH] e4defrag: Handle device symlinks Eric Sandeen
2012-07-19 19:04 ` Eric Sandeen
2012-07-28 21:54 ` Theodore Ts'o
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).