Unoffical empeg BBS

Quick Links: Empeg FAQ | RioCar.Org | Hijack | BigDisk Builder | jEmplode | emphatic
Repairs: Repairs

Topic Options
#305213 - 18/12/2007 02:56 Esoteric Linux question: bind mounts
tonyc
carpal tunnel

Registered: 27/06/1999
Posts: 7058
Loc: Pittsburgh, PA
A question for Linux hackers...

On my file server, I have several logical partitions, one of which holds all of my media. This partition is mounted at /mnt/media, but for simplicity, I've added some bind mounts under / to make my paths shorter. Here are the relevant lines in my fstab:

 Code:
/dev/vg00/media         /mnt/media              jfs     defaults,noatime 1 1
/mnt/media/incoming     /incoming               none    rw,bind         0 0
/mnt/media/music        /music                  none    rw,bind         0 0
/mnt/media/photo        /photo                  none    rw,bind         0 0
/mnt/media/video        /video                  none    rw,bind         0 0


I was using symbolic links instead of bind mounts before, but was having problems traversing them properly from CIFS clients. I think I figured out the smb.conf magic to solve most of those problems, but in that process, discovered bind mounts, and figured they were a better fit for my setup.

The problem I'm having now is that moving files between these bind mounted partitions is slow. For example, say I'm in /incoming ("real" path /mnt/media/incoming) and I want to move a file to /video ("real" path /mnt/media/video). In reality, this is a move on the same partition, and should be instantaneous. However, when I do this, it takes a long time, because the system is clearly copying the entire file. In fact, if I cd to /mnt/media/incoming/video and do a "mv file ../video", the move is instantaneous, as expected.

I think what's happening is that the system doesn't realize that the source and destination mounts are actually on the same partition. So, why not?



Edited by tonyc (18/12/2007 02:58)
_________________________
- Tony C
my empeg stuff

Top
#305218 - 18/12/2007 06:17 Re: Esoteric Linux question: bind mounts [Re: tonyc]
Shonky
pooh-bah

Registered: 12/01/2002
Posts: 2009
Loc: Brisbane, Australia
The problem you're having right is you have set this up to make one filesystem look like some separate ones.

But that of course means the system then thinks they really are different i.e. it will run separate file system instances then won't it? I assume that's the basically the answer to your "why not"?

Can't have the best of both worlds maybe?

It must be somewhere in between (one fs and two) though since really it's a single file system that needs to be kept in sync.

Sorry don't have an answer for you.
_________________________
Christian
#40104192 120Gb (no longer in my E36 M3, won't fit the E46 M3)

Top
#305265 - 18/12/2007 20:01 Re: Esoteric Linux question: bind mounts [Re: tonyc]
mlord
carpal tunnel

Registered: 29/08/2000
Posts: 14493
Loc: Canada
 Originally Posted By: tonyc

I think what's happening is that the system doesn't realize that the source and destination mounts are actually on the same partition. So, why not?


Mmmm.. I think I would call that a bug, because clearly it should work as you expected it to.

EDIT: Most likely a bug in whatever program you're using to move the files around.
It should try to use link(2) first, and then fall back on a file copy if that fails.

You might be able to use strace on the command to see what it is doing.


Cheers


Edited by mlord (18/12/2007 20:03)

Top
#305266 - 18/12/2007 20:05 Re: Esoteric Linux question: bind mounts [Re: mlord]
mlord
carpal tunnel

Registered: 29/08/2000
Posts: 14493
Loc: Canada
 Originally Posted By: mlord
 Originally Posted By: tonyc

I think what's happening is that the system doesn't realize that the source and destination mounts are actually on the same partition. So, why not?


Mmmm.. I think I would call that a bug, because clearly it should work as you expected it to.

EDIT: Most likely a bug in whatever program you're using to move the files around.
It should try to use link(2) first, and then fall back on a file copy if that fails.

You might be able to use strace on the command to see what it is doing.


Oh, wait. It's a kernel deficiency. From the link(2) manpage:

Linux permits a filesystem to be mounted at multiple points,
but link(2) does not work across different mount points,
even if the same filesystem is mounted on both.


So that's a shortcoming of the link(2) system call on Linux.

Cheers


Edited by mlord (18/12/2007 20:06)

Top
#305269 - 18/12/2007 20:17 Re: Esoteric Linux question: bind mounts [Re: mlord]
tonyc
carpal tunnel

Registered: 27/06/1999
Posts: 7058
Loc: Pittsburgh, PA
Ah, okay. Oddly, the man page on my system doesn't have that caveat listed. For the EXDEV error, it just says "oldpath and newpath are not on the same filesystem."

I guess I'll try switching back to symlinks instead of bind mounts.
_________________________
- Tony C
my empeg stuff

Top
#305273 - 18/12/2007 20:49 Re: Esoteric Linux question: bind mounts [Re: tonyc]
mlord
carpal tunnel

Registered: 29/08/2000
Posts: 14493
Loc: Canada
If you want to be able to do this, here (attached) is a simple kernel patch that I just now cooked up to allow it. It seems to work under light testing here on my own machine.

I'm also posting to LKML to find out more from the filesystem gurus.

Cheers


Attachments
link_across_binds.patch (124 downloads)


Top
#305274 - 18/12/2007 21:49 Re: Esoteric Linux question: bind mounts [Re: mlord]
music
addict

Registered: 25/06/2002
Posts: 456
 Originally Posted By: mlord
If you want to be able to do this, here (attached) is a simple kernel patch that I just now cooked up


Mark, you are amazing!
Wow.

Top
#305275 - 18/12/2007 22:05 Re: Esoteric Linux question: bind mounts [Re: mlord]
tfabris
carpal tunnel

Registered: 20/12/1999
Posts: 31597
Loc: Seattle, WA
And thus we see the advantages of a) Linux and b) being acquainted with the Linux IDE Guy. \:\)
_________________________
Tony Fabris

Top
#305284 - 19/12/2007 01:39 Re: Esoteric Linux question: bind mounts [Re: tonyc]
mlord
carpal tunnel

Registered: 29/08/2000
Posts: 14493
Loc: Canada
 Originally Posted By: tonyc
Ah, okay. Oddly, the man page on my system doesn't have that caveat listed. For the EXDEV error, it just says "oldpath and newpath are not on the same filesystem."

I guess I'll try switching back to symlinks instead of bind mounts.


The answer from the filesystem gurus, is that the restriction is (1) artificial, and (2) deliberate. It's there to enable a way to impose extra security on a multi-user system.

But for a single-user system (single regular user, "you", plus the superuser "root"), there's no need. So the patch I posted ought to be safe for your own machines.

Cheers


Edited by mlord (19/12/2007 01:51)

Top
#305285 - 19/12/2007 01:42 Re: Esoteric Linux question: bind mounts [Re: mlord]
mlord
carpal tunnel

Registered: 29/08/2000
Posts: 14493
Loc: Canada
..and here (attached) is the simplified version of the patch, without the "printk" (kernel log) line and associated logic.

Cheers


Attachments
link_across_binds.patch (122 downloads)


Top
#305286 - 19/12/2007 01:53 Re: Esoteric Linux question: bind mounts [Re: mlord]
tonyc
carpal tunnel

Registered: 27/06/1999
Posts: 7058
Loc: Pittsburgh, PA
Yeah, I saw the response on LKML. Thanks for looking into it. I don't think I'm going to want to have to recompile the kernel with each new version, so I think I'll just go path of least resistance and change the bind mounts back to symlinks.
_________________________
- Tony C
my empeg stuff

Top
#305293 - 19/12/2007 12:23 Re: Esoteric Linux question: bind mounts [Re: tfabris]
LittleBlueThing
addict

Registered: 11/01/2002
Posts: 612
Loc: Reading, UK
 Originally Posted By: tfabris
And thus we see the advantages of a) Linux

Well, opensource \:\)

I was futzing around on my pictureframe on friday and couldn't get X to start without a cursor. A quick 'apt-get source', an irc chat and a few minutes (about an hour actually) and Xorg will have a -nocursor option in the next release - *so* cool.
_________________________
LittleBlueThing Running twin 30's

Top
#305305 - 19/12/2007 16:34 Re: Esoteric Linux question: bind mounts [Re: LittleBlueThing]
music
addict

Registered: 25/06/2002
Posts: 456
 Originally Posted By: LittleBlueThing
and Xorg will have a -nocursor option in the next release - *so* cool.


Thank you!
I will also find that very useful. (And for the same reasons.)

Top