[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <91b13c310710311115m13f60cecnaffd9c8428d33d05@mail.gmail.com>
Date: Thu, 1 Nov 2007 02:15:33 +0800
From: "rae l" <crquan@...il.com>
To: "Greg KH" <gregkh@...e.de>
Cc: linux-kernel@...r.kernel.org
Subject: Re: [PATCH] [sysfs]: make readlink result shorter when the symlink and its target shared some base sysfs subdirectory
On 10/31/07, Greg KH <gregkh@...e.de> wrote:
> On Wed, Oct 31, 2007 at 06:34:20PM +0800, Denis Cheng wrote:
> > this is especially useful after /sys/slab introduced, for example:
> >
> > $ ls -l /sys/slab/mm_struct
> > lrwxrwxrwx 1 root root 0 2007-10-31 17:40 /sys/slab/mm_struct -> :0000448
> >
> > instead of:
> >
> > $ ls -l /sys/slab/mm_struct
> > lrwxrwxrwx 1 root root 0 2007-10-31 17:40 /sys/slab/mm_struct -> ../slab/:0000448
> >
> > Signed-off-by: Denis Cheng <crquan@...il.com>
>
> As pretty as this change is, it's not really necessary, right?
I don't think so.
Suppose to create a symlink on the disk, say /usr/src/linux, that
points to /usr/src/linux-2.6.23, the best way is:
# cd /usr/src/
# ln -s linux-2.6.23 linux
# ls -l linux
# ls -l linux
lrwxrwxrwx 1 root root 14 2007-10-16 19:21 linux -> linux-2.6.23
other than:
# cd /usr/src/
# ln -s /usr/src/linux-2.6.23 linux
or
# ln -s ../../usr/src/linux-2.6.23 linux
# ls -l linux
lrwxrwxrwx 1 root root 14 2007-10-16 19:21 linux -> ../../usr/src/linux-2.6.23
Anyone know this, since sysfs is also a filesystem, it should conform
the perfect way.
For another point, consider the code in fs/sysfs/symlink.c:
static int sysfs_get_target_path(struct sysfs_dirent * parent_sd,
struct sysfs_dirent * target_sd, char *path)
{
...
size = object_path_length(target_sd) + depth * 3 - 1;
if (size > PATH_MAX)
return -ENAMETOOLONG;
Since having longer readlink result would consume more memory on the
output parameter path, that is error prone to return -ENAMETOOLONG; we
just need the shorter readlink result.
>
> Is there any other place in /sys that would benefit from this?
Yes. there are already some other symlinks those are also not crossing
top subdirectory of /sys, they would benefit from this patch:
I have found all of them by this little shell:
$ find /sys -type l -printf '%p -> %l -> ' -exec readlink -f '{}' \; | gawk '{
split($1, a, "/");
split($5, b, "/");
if (a[3] == b[3])
print;
}'
that will print many lines like:
...
/sys/block/hdd/subsystem -> ../../block -> /sys/block
/sys/module/snd_mixer_oss/holders/snd_pcm_oss ->
../../../module/snd_pcm_oss -> /sys/module/snd_pcm_oss
/sys/class/sound/audio/subsystem -> ../../../class/sound -> /sys/class/sound
/sys/class/pci_bus/0000:00/subsystem -> ../../../class/pci_bus ->
/sys/class/pci_bus
...
>
> thanks,
>
> greg k-h
>
--
Denis Cheng
Linux Application Developer
"One of my most productive days was throwing away 1000 lines of code."
- Ken Thompson.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists