OT: why no file copy() libc/syscall ??
Quoted 1 line
It is too simple to implement in user mode.
That works for a plain byte-stream on a local UNIX-style filesystem. (though it likely isn't the fastest)
It doesn't work for Macintosh files. It's too slow for CIFS over a modem. It doesn't work for Windows security data. It doesn't allow copy-on-write files. It eats CPU time on compressed filesystems.
Quoted 5 lines
The security context of the output depends on the user process. If it is a privileged process (ie, may change the context of the result) then the user process has to setup that context before the file is copied.
So open the file, change context, and then:
long copy_fd_to_file(int fd, const char *name, ...)
(if you can no longer read from the OPEN fd, either we override that or we just don't care about such mostly-fictional cases)
Quoted 6 lines
There are also some issues with mandatory security controls. If it is copied in kernel mode, then the previous labels could be automatically carried over to the resulting file... But that may not be what you want (and frequently, it isn't).
If it matters:
// security as if a new file were created #define CF_REPLACE_SECURITY 0x00000001 // if unable to replicate, up or down? #define CF_ROUND_SECURITY_UP 0x00000002 #define CF_ROUND_SECURITY_DOWN 0x00000004 // fail if security can't be replicated #define CF_SECURITY_EXACT 0x00000008
Quoted 2 lines
Now back to the copy.. You don't have to use a read/write loop- mmap is faster.
It's slower. (this is Linux, not SunOS) Use a 4 kB or 8 kB read/write loop.
Quoted 7 lines
And this is the other reason for not doing it in Kernel mode. Buffer management of this type is much easier in user space since the copy procedure doesn't have to deal with memory limitations, cache flushes page faulting of processes unrelated to the copy, but is related to cache pressure.
Buffer management is very much a kernel thing.
Quoted 10 lines
Quoted 7 lines
Is it? Please explain the simple steps which cp(1) should take in order to observe that it is being asked to duplicate a file on a file system such as CIFS (or NFSv4?) which allows the client to issue a 'copy file' command over the network without actually transferring the data twice, and to invoke such a command.
Ah. That is an optimization question, not a question of kernel/user mode.
Note that /bin/cp isn't always going to have the necessary passwords and such. You're headed down a path toward setuid /bin/cp.
Quoted 7 lines
Since the error checking for source and destination both include doing a stat and statfs, the device information (and FS info) can both be retrieved.
And mmap doesn't require data transfer "twice" (local copy).
Huh? Over the network from server to client counts as once. Then /bin/cp gets the data. Then it goes back over the network from the client to the server. That's "twice". That's horribly painful for a multi-gigabyte file and a DSL or cable-modem connection, never mind a dial-up connection.
Quoted 6 lines
Since that copy only pagefaults (though read/write may be faster for some files
- I thought that was true for small files that fit in cache, and large files faster via mmap and depends on the page size; and the tradeoff would be system dependant).
Keep the read/write loop small for speed.
Quoted 12 lines
And since both source and destination may be remote you do get to decide based on source and destination devices: if they are the same, and one on a remote node, then BOTH will be on the remote, then you get to use the CIFS/NFS file copy. (check the doc on "stat/statfs" for additional info).
I don't believe it works when source and destination are on DIFFERENT remote nodes, though.
Quoted 6 lines
Strictly up to the implementation of cp/mv.
Though you will loose portability of cp/mv. (Of course, you also loose it with a syscall for file copy too; as well as the MUCH more complicated implementation/security checks).
Doing that in cp/mv is just insane. For one, it bypasses any local security control over access to the filesystem. There's not even a way to be sure you're dealing with the server you think you're dealing with.
Quoted 11 lines · Albert Cahalan
Quoted 1 line
It is too simple to implement in user mode.
That works for a plain byte-stream on a local UNIX-style filesystem. (though it likely isn't the fastest)
It doesn't work for Macintosh files. It's too slow for CIFS over a modem. It doesn't work for Windows security data. It doesn't allow copy-on-write files. It eats CPU time on compressed filesystems.
Having a sys_copy() syscall would be incredibly useful for Lustre (distributed Linux fs). We could start a copy from one storage node to another (or more likely many to many for a file striped over many storage nodes) at num_stripes * uni-directional bandwidth with no impact to the client node. Instead, we have to copy files at best a single client's bi-directional network_bandwidth.
Cheers, Andreas
--
Andreas Dilger
http://sourceforge.net/projects/ext2resize/
http://www-mddsp.enel.ucalgary.ca/People/adilger/
Quoted 6 lines · Andreas Dilger
Having a
sys_copy()syscall would be incredibly useful for Lustre (distributed Linux fs). We could start a copy from one storage node to another (or more likely many to many for a file striped over many storage nodes) atnum_stripes* uni-directional bandwidth with no impact to the client node. Instead, we have to copy files at best a single client's bi-directionalnetwork_bandwidth.
Plus a sys_copy() syscall could be used as a generic way for filesystems to set up Copy-on-Write. Right now, you'd need to have userspace call sys-reiser4 or something like that.
Signature · 1 line
Daniel Gryniewicz <[email protected]>
Quoted 3 lines · Daniel Gryniewicz
Plus a
sys_copy()syscall could be used as a generic way for filesystems to set up Copy-on-Write. Right now, you'd need to have userspace call sys-reiser4 or something like that.
This is fast turning into a creeping horror of aggregation. I defy anybody to create an API to cover all the options mentioned so far and *not* have it look like the process_clone horror we so roundly derided a few weeks ago.
Quoted 8 lines · On Nov 10, 2003 23:14 -0500, [email protected] wrote:
Quoted 3 lines · Daniel Gryniewicz
Plus a
sys_copy()syscall could be used as a generic way for filesystems to set up Copy-on-Write. Right now, you'd need to have userspace call sys-reiser4 or something like that.This is fast turning into a creeping horror of aggregation. I defy anybody to create an API to cover all the options mentioned so far and *not* have it look like the
process_clonehorror we so roundly derided a few weeks ago.
int sys_copy(int fd_src, int fd_dst)
It is up to the filesystem to decide if both files are on the same device and can be copied with a copy RPC (or whatever). If the filesystem returns -EOPNOTSUPP then the VFS goes into a simple readpages/writepages loop to do the copy instead, maybe also copying ACLs or other things the VFS understands.
All of the "extra functionality" is being handled in the filesystem itself and not the VFS or the API. Copy-on-write is an fs-internal issue depending on whether fs supports it, how it was mounted, etc. Remote copy is also an fs-internal issue depending on whether inodes are in same filesystem, support, etc. You might get into fun things like doing zero-copy.
Telling the filesystem we are doing a copy vs. a bunch of reads mixed with a bunch of writes is just semantically something that the filesystem should know about.
Cheers, Andreas
--
Andreas Dilger
http://sourceforge.net/projects/ext2resize/
http://www-mddsp.enel.ucalgary.ca/People/adilger/
Quoted 6 lines · Andreas Dilger
Quoted 5 lines · Albert Cahalan
Quoted 1 line
It is too simple to implement in user mode.
That works for a plain byte-stream on a
local UNIX-style filesystem. (though it
likely isn't the fastest)
It would be something similar than sendfile() ?
- Gábor (larta'H)
Quoted 5 lines · Andreas Dilger
Quoted 3 lines
This is fast turning into a creeping horror of aggregation. I defy anybody to create an API to cover all the options mentioned so far and *not* have it look like the
process_clonehorror we so roundly derided a few weeks ago.int
sys_copy(int fd_src, int fd_dst)
Doesn't work. You have to set the security attributes while you open fd_dst.
Quoted 7 lines · Florian Weimer
Quoted 5 lines · Andreas Dilger
Quoted 3 lines
This is fast turning into a creeping horror of aggregation. I defy anybody to create an API to cover all the options mentioned so far and *not* have it look like the
process_clonehorror we so roundly derided a few weeks ago.int
sys_copy(int fd_src, int fd_dst)
That sounds a lot like a sendfile with a file as the destination. Useful but still happening on the local system. My understanding was that this was to be sent to a remote system where the file descriptors might not be open.
Quoted 3 lines
Doesn't work. You have to set the security attributes while you open
fd_dst.
That would have been done with open().
To operate on paths so it could be sent to a fileserver it would need the same arguments as open() with the addition of the newpath.
int sys_copy(const char *oldpath, const char *oldpath, int flags, mode_t mode);
O_TRUNC replace an existing file.O_EXCL prevent replacing an existing file.O_APPEND concatenate (useful feature creep).
O_NDELAY/O_NONBLOCK return and ignore ENOSPACE condition, ick!O_SYNC if O_SYNC supported for openO_NOFOLLOW don't follow symlink (no need for a lcopy())
EXDEV (see link(2)) seems a better error code for cases where the source and destination are on different servers. Otherwise the error codes would conform to open(2).
I've long thought a file copy syscall was missing from unix but until you start networking it isn't an issue.
Signature · 5 lines
________________________________________________________________ J.W. Schultz Pegasystems Technologies email address: [email protected] Remember Cernan and Schmitt
Quoted 7 lines · Albert Cahalan
So open the file, change context, and then:
long
copy_fd_to_file(int fd, const char *name, ...)(if you can no longer read from the OPEN fd,
either we override that or we just don't care
about such mostly-fictional cases)
Actually, I think we should have a:
long copy_fd_to_fd (int src, int dst, int len)
type of systemcall.
It should do something like:
while ((nbytes = read (src, buf, BUFSIZE)) >= 0) {
if (write (dst, buf, nbytes) < 0)
return totbytes;
totbytes += nbytes;
}but it allows kernel-space to optimize this whenever possible. Kernel then becomes responsible for detecting and handling the optimizable cases.
The kernel then becomes something
if (islocalfile (src) && issocket (dst)) /* Call the old sendfile */ return sendfile (....); if (isCIFS (src), isCIFS(dst)) /* Tell remote host to copy the file. */ return CIFS_copy_file (....); ...
and then the default implementation. This is nice and expandible, and provides a default for the case that cannot be optimized.
And if you don't want the extra code, we could enclose the different optimizations with ifdefs.
But alas, last time Linus didn't agree with me and decided we should do something like "sendfile", which is IMHO just a special case of this one.
If we implement this in kernel (at first just the copy_fd_fd and the default implementation), then we can get "cp" to use this, and then suddenly whenever we upgrade the kernel, cp can use the newly optimized copying mechanism. (e.g. whenever we manage to specify a socket as the destination, cp would suddenly start to use "sendfile"!!)
(It might be better to include a "buffer" argument in the interface, freeing the implementation of allocating a buffer when an optimization is not possible).
Roger.
Signature · 3 lines
** [email protected] ** http://www.BitWizard.nl/ ** +31-15-2600998 ** *-- BitWizard writes Linux device drivers for any device you may have! --* **** "Linux is like a wigwam - no windows, no gates, apache inside!" ****
Quoted 10 lines · Rogier Wolff
Quoted 7 lines · Albert Cahalan
So open the file, change context, and then:
long
copy_fd_to_file(int fd, const char *name, ...)(if you can no longer read from the OPEN fd,
either we override that or we just don't care
about such mostly-fictional cases)
Quoted 5 lines
Actually, I think we should have a:
long
copy_fd_to_fd(int src, int dst, int len)type of systemcall.
We have one, sendfile(2).
Quoted 14 lines
It should do something like:
while ((nbytes = read (src, buf, BUFSIZE)) >= 0) { if (write (dst, buf, nbytes) < 0) return totbytes; totbytes += nbytes; }but it allows kernel-space to optimize this whenever possible. Kernel then becomes responsible for detecting and handling the optimizable cases.
The kernel then becomes something
Quoted 9 lines
if (islocalfile (src) && issocket (dst)) /* Call the old sendfile */ return sendfile (....); if (isCIFS (src), isCIFS(dst)) /* Tell remote host to copy the file. */ return CIFS_copy_file (....); ...
Can you explain why this cannot be in sys_sendfile?
It doesn't make much sense to provide any default in the kernel, that's something the userland can handle equally well. But e.g. the CIFS copy can be done as sendfile hook.
Jakub
Quoted 1 line · Jakub Jelinek
But e.g. the CIFS copy can be done as sendfile hook.
Can it? I thought it took filenames.
Signature · 1 line
dwmw2
Quoted 10 lines · Rogier Wolff
Quoted 7 lines · Albert Cahalan
So open the file, change context, and then:
long
copy_fd_to_file(int fd, const char *name, ...)(if you can no longer read from the OPEN fd,
either we override that or we just don't care
about such mostly-fictional cases)
Quoted 5 lines
Actually, I think we should have a:
long
copy_fd_to_fd(int src, int dst, int len)type of systemcall.
I don't think that works. To have a destination file descriptor, you have to already have created the destination file. Having done so, it may now be impossible to transfer the security data. This is especially the case with network filesystems.
I can well imagine providing a file descriptor for the destination directory and making the filename optional. This helps pin things down if there's worry about an attacker moving directories, and it neatly allows for fully anonymous temporary files if a file descriptor is returned.
Quoted 7 lines · jw schultz
Quoted 6 lines · Florian Weimer
Quoted 4 lines · Andreas Dilger
Quoted 3 lines
This is fast turning into a creeping horror of aggregation. I defy anybody to create an API to cover all the options mentioned so far and *not* have it look like the
process_clonehorror we so roundly derided a few weeks ago.
Quoted 6 lines
Quoted 1 line
Quoted 1 line
int
sys_copy(int fd_src, int fd_dst)That sounds a lot like a sendfile with a file as the destination. Useful but still happening on the local system. My understanding was that this was to be sent to a remote system where the file descriptors might not be open.
It probably should be sendfile, where the destination fd is a local file instead of a socket. We really do not want to pass pathnames down into the filesystem layer. As far as I know, no existing VFS operation does that and it probably isn't a good idea to start doing it now.
Somehow the filesystem that 'hosts' the src_fd object should get a chance to see/intercept the sendfile syscall, and it can then decide based on the dst_fd object what to do. If the destination happens to be in the same filesystem it could possibly use a special internal copyfile rpc call or CoW implementation.
The userspace/libc code could provide a copyfile(char* src, char* dst, int flags, int mode) wrapper, which can also handle falling back to a simple read/write loop when sendfile fails.
So we clearly don't need a new system call, sendfile would do fine and interestingly the manual page I'm reading now mentions that the source has to be a mmap-able object, but lists no such restrictions on the destination fd. Maybe sendfile already works and we just need to give the filesystems a chance to override it.
Jan
Quoted 5 lines · Albert Cahalan
Quoted 1 line
It is too simple to implement in user mode.
That works for a plain byte-stream on a local UNIX-style filesystem. (though it likely isn't the fastest)
Yes - this was the local copy
Quoted 12 lines
It doesn't work for Macintosh files. It's too slow for CIFS over a modem. It doesn't work for Windows security data. It doesn't allow copy-on-write files. It eats CPU time on compressed filesystems.
Quoted 5 lines
The security context of the output depends on the user process. If it is a privileged process (ie, may change the context of the result) then the user process has to setup that context before the file is copied.
Quoted 3 lines
So open the file, change context, and then:
long
copy_fd_to_file(int fd, const char *name, ...)
Easy to do in user mode.
Quoted 4 lines
(if you can no longer read from the OPEN fd, either we override that or we just don't care about such mostly-fictional cases)
correct - If you can't read, fail.
Quoted 17 lines
Quoted 6 lines
There are also some issues with mandatory security controls. If it is copied in kernel mode, then the previous labels could be automatically carried over to the resulting file... But that may not be what you want (and frequently, it isn't).
If it matters:
// security as if a new file were created #define
CF_REPLACE_SECURITY0x00000001// if unable to replicate, up or down? #defineCF_ROUND_SECURITY_UP0x00000002#defineCF_ROUND_SECURITY_DOWN0x00000004// fail if security can't be replicated #defineCF_SECURITY_EXACT0x00000008
Quoted 5 lines
Quoted 2 lines
Now back to the copy.. You don't have to use a read/write loop- mmap is faster.
It's slower. (this is Linux, not SunOS) Use a 4 kB or 8 kB read/write loop.
yup local.
Quoted 9 lines
Quoted 7 lines
And this is the other reason for not doing it in Kernel mode. Buffer management of this type is much easier in user space since the copy procedure doesn't have to deal with memory limitations, cache flushes page faulting of processes unrelated to the copy, but is related to cache pressure.
Buffer management is very much a kernel thing.
Yes it is, but do you want to push process dependant buffer management into the page management? It's just easier to do this in user mode, and allow the kernel to handle global page managment.
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Is it? Please explain the simple steps which cp(1) should take in order to observe that it is being asked to duplicate a file on a file system such as CIFS (or NFSv4?) which allows the client to issue a 'copy file' command over the network without actually transferring the data twice, and to invoke such a command.
Quoted 6 lines
Quoted 2 lines
Ah. That is an optimization question, not a question of kernel/user mode.
Note that
/bin/cpisn't always going to have the necessary passwords and such. You're headed down a path toward setuid/bin/cp.
If cp doesn't have access to the proper security credentials, then the file should not be copied.
Quoted 8 lines
Quoted 7 lines
Since the error checking for source and destination both include doing a stat and statfs, the device information (and FS info) can both be retrieved.
And mmap doesn't require data transfer "twice" (local copy).
Quoted 7 lines
Huh? Over the network from server to client counts as once. Then
/bin/cpgets the data. Then it goes back over the network from the client to the server. That's "twice". That's horribly painful for a multi-gigabyte file and a DSL or cable-modem connection, never mind a dial-up connection.
True for all networked file systems. I had ment to say (local filesystem copy).
Quoted 8 lines
Quoted 6 lines
Since that copy only pagefaults (though read/write may be faster for some files
- I thought that was true for small files that fit in cache, and large files faster via mmap and depends on the page size; and the tradeoff would be system dependant).Keep the read/write loop small for speed.
yes.
Quoted 19 lines
Quoted 12 lines
And since both source and destination may be remote you do get to decide based on source and destination devices: if they are the same, and one on a remote node, then BOTH will be on the remote, then you get to use the CIFS/NFS file copy. (check the doc on "stat/statfs" for additional info).
I don't believe it works when source and destination are on DIFFERENT remote nodes, though.
Quoted 6 lines
Strictly up to the implementation of cp/mv.
Though you will loose portability of cp/mv. (Of course, you also loose it with a syscall for file copy too; as well as the MUCH more complicated implementation/security checks).
Quoted 5 lines
Doing that in cp/mv is just insane. For one, it bypasses any local security control over access to the filesystem. There's not even a way to be sure you're dealing with the server you think you're dealing with.
It shouldn't matter - first the source file must be opened for read AND the destination file opened for write. This should give the proper local security evaluation and context for the copy. Once this has been approved, the remote copy request can be made (provided they are on the same "networked" device). Just making
the request still doesn't mean that it will succeed - after all, the final security decisions are made by the remote server implementing the file copy.
Though if the copy is valid locally, then the use of the filesystem supported copy should work. It is an equivalent operation, it just all takes place on the server.
Identity of the server is irrelevent, as long as it is the same server (or farm) for both source and destination. If the remote file copy is defined, then it should work even when the actual source and destination are different physical machines - the remote filesystem CLAIMS it will work (identical is determined from the "device" mounted, one mount, one device as far as network filesystems go). And if they are not identical then you fall back to using a local copy.
All bets are off if the local pathnames are required by the remote server. That is silly. How would a networked client even know what the pathname would be? The parameters should be the two file handles passed to the remote filesystem.
Personally, I don't think any changes should be made. It's just that this level of transfer is what the original poster was talking about. It just shouldn't be done in kernel mode.
Quoted 10 lines · Florian Weimer
Quoted 6 lines · Andreas Dilger
Quoted 4 lines
This is fast turning into a creeping horror of aggregation. I defy anybody to create an API to cover all the options mentioned so far and *not* have it look like the
process_clonehorror we so roundly derided a few weeks ago.int
sys_copy(int fd_src, int fd_dst)Doesn't work. You have to set the security attributes while you open
fd_dst.
Why? the open for fd_src should have the security attributes (both locally and in the file server if networked). Opening fd_dst should SET the security attributes desired (again, locally and in the target fileserver).
Then the sys_copy(fd_src,fd_dst) can take place in the FS code. And of course it is necessary that fd_src and fd_dst reside on the same device. If they don't, then the sys_copy should fail.
If the sys_copy is a remote filesystem then fd_src, and fd_dst must be replaced by the remote file handles and this passed to the remote server. Any additional checks may then be made from the evaluation of the file handles locally on the file server, using the security credentials belonging to the file handles.
Followup to: <[email protected]> By author: Jakub Jelinek <[email protected]> In newsgroup: linux.dev.kernel
Quoted 9 lines
Quoted 6 lines
Actually, I think we should have a:
long
copy_fd_to_fd(int src, int dst, int len)type of systemcall.
We have one, sendfile(2).
It would be very nice if we could (a) expand the uses of sendfile(2), and (b) have the libc do the fallback to read/write/mmap as needed.
-hpa
Signature · 4 lines
<[email protected]> at work, <[email protected]> in private! If you send me mail in HTML format I will assume it's spam. "Unix gives you enough rope to shoot yourself in the foot." Architectures needed: ia64 m68k mips64 ppc ppc64 s390 s390x sh v850 x86-64
Quoted 8 lines · H. Peter Anvin
Followup to: <[email protected]> By author: Jakub Jelinek <[email protected]> In newsgroup: linux.dev.kernelQuoted 5 lines
Quoted 5 lines
Actually, I think we should have a:
long
copy_fd_to_fd(int src, int dst, int len)
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
type of systemcall.
We have one, sendfile(2).
It would be very nice if we could (a) expand the uses of sendfile(2), and (b) have the libc do the fallback to read/write/mmap as needed.
I actually hacked cp for a while and it improved cp some point percent on normal machines.
See ftp://ftp.suse.com/pub/people/andrea/cp-sendfile/
the main downside and the reason it wasn't applied IIRC is the lack of interruption of sendfile, basically for an huge file it would take a while before C^c has any effect. The kernel isn't interrupting the syscall. This is no different from a huge read or write syscall (but read/write are never huge or the buffer would need to be huge too, not the case for sendfile that works zerocopy), so in theory we could workaround it by entering/exiting kernel multiple times just to allow the signal to be handled like in the read/write case.
Quoted 22 lines · Andrea Arcangeli
Quoted 8 lines · H. Peter Anvin
Followup to: <[email protected]> By author: Jakub Jelinek <[email protected]> In newsgroup: linux.dev.kernelQuoted 5 lines
Quoted 5 lines
Actually, I think we should have a:
long
copy_fd_to_fd(int src, int dst, int len)Quoted 7 lines
Quoted 4 lines
Quoted 1 line
type of systemcall.
We have one, sendfile(2).
It would be very nice if we could (a) expand the uses of sendfile(2), and (b) have the libc do the fallback to read/write/mmap as needed.
I actually hacked cp for a while and it improved cp some point percent on normal machines.
See ftp://ftp.suse.com/pub/people/andrea/cp-sendfile/
Quoted 8 lines
the main downside and the reason it wasn't applied IIRC is the lack of interruption of sendfile, basically for an huge file it would take a while before C^c has any effect. The kernel isn't interrupting the syscall. This is no different from a huge read or write syscall (but read/write are never huge or the buffer would need to be huge too, not the case for sendfile that works zerocopy), so in theory we could workaround it by entering/exiting kernel multiple times just to allow the signal to be handled like in the read/write case.
Until interrupt and restart (as has been discussed here for other syscalls) handling is improved there could be a sanity check with an E2BIG or something if the size is insane. I dislike the thought of sendfile going sitting in D state on a multi-gigabyte file.
Signature · 5 lines
________________________________________________________________ J.W. Schultz Pegasystems Technologies email address: [email protected] Remember Cernan and Schmitt
Quoted 6 lines · Andrea Arcangeli
I actually hacked cp for a while and it improved cp some point percent on normal machines.
See ftp://ftp.suse.com/pub/people/andrea/cp-sendfile/
Quoted 8 lines
the main downside and the reason it wasn't applied IIRC is the lack of interruption of sendfile, basically for an huge file it would take a while before C^c has any effect. The kernel isn't interrupting the syscall. This is no different from a huge read or write syscall (but read/write are never huge or the buffer would need to be huge too, not the case for sendfile that works zerocopy), so in theory we could workaround it by entering/exiting kernel multiple times just to allow the signal to be handled like in the read/write case.
... or we could put in checks into the kernel for signal pending, and return EINTR.
-hpa
Quoted 2 lines · H. Peter Anvin
... or we could put in checks into the kernel for signal pending, and return EINTR.
that would be even better indeed.
Quoted 7 lines · Andrea Arcangeli
Quoted 2 lines · H. Peter Anvin
... or we could put in checks into the kernel for signal pending, and return EINTR.
that would be even better indeed.
s/EINTR/short count/, of course :)
-hpa
Quoted 8 lines · Jesse Pollard
Quoted 6 lines · Albert Cahalan
Quoted 5 lines
The security context of the output depends on the user process. If it is a privileged process (ie, may change the context of the result) then the user process has to setup that context before the file is copied.
Quoted 5 lines
Quoted 3 lines
So open the file, change context, and then:
long
copy_fd_to_file(int fd, const char *name, ...)Easy to do in user mode.
It isn't, because the user-mode code would need to have a full understanding of whatever fancy (seLinux, RSBAC, lomac...) security mechanism the kernel is using. It's not enough to just know about switching to some named context via a common API.
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 7 lines
Is it? Please explain the simple steps which cp(1) should take in order to observe that it is being asked to duplicate a file on a file system such as CIFS (or NFSv4?) which allows the client to issue a 'copy file' command over the network without actually transferring the data twice, and to invoke such a command.
Ah. That is an optimization question, not a question of kernel/user mode.
Quoted 6 lines
Quoted 3 lines
Note that
/bin/cpisn't always going to have the necessary passwords and such. You're headed down a path toward setuid/bin/cp.If cp doesn't have access to the proper security credentials, then the file should not be copied.
You have proper credentials for access through the mounted filesystem. That filesystem was mounted by root, using some secret key that is specific to the local machine. You could try to directly contact the server over the network, but you won't have the keys.
You're allowed to indirectly use the keys by going through the mounted filesystem. For example, you can call rmdir() to remove a directory but you can not cause the same effect by sending a message over the network directly to the server. You have no ability to bypass the local kernel.
So you can copy that file, but you have to use the file-oriented system calls to do it. You'll need kernel support to invoke a remote-copy operation. (or a setuid-root /bin/cp that looks up the keys, determines the correct server, makes a network connection, etc.)
Quoted 49 lines
Quoted 19 lines
Quoted 12 lines
And since both source and destination may be remote you do get to decide based on source and destination devices: if they are the same, and one on a remote node, then BOTH will be on the remote, then you get to use the CIFS/NFS file copy. (check the doc on "stat/statfs" for additional info).
I don't believe it works when source and destination are on DIFFERENT remote nodes, though.
Quoted 6 lines
Strictly up to the implementation of cp/mv.
Though you will loose portability of cp/mv. (Of course, you also loose it with a syscall for file copy too; as well as the MUCH more complicated implementation/security checks).
Quoted 5 lines
Doing that in cp/mv is just insane. For one, it bypasses any local security control over access to the filesystem. There's not even a way to be sure you're dealing with the server you think you're dealing with.
It shouldn't matter - first the source file must be opened for read AND the destination file opened for write. This should give the proper local security evaluation and context for the copy. Once this has been approved, the remote copy request can be made (provided they are on the same "networked" device). Just making
the request still doesn't mean that it will succeed - after all, the final security decisions are made by the remote server implementing the file copy.Though if the copy is valid locally, then the use of the filesystem supported copy should work. It is an equivalent operation, it just all takes place on the server.
Identity of the server is irrelevent, as long as it is the same server (or farm) for both source and destination. If the remote file copy is defined, then it should work even when the actual source and destination are different physical machines - the remote filesystem CLAIMS it will work (identical is determined from the "device" mounted, one mount, one device as far as network filesystems go). And if they are not identical then you fall back to using a local copy.
Quoted 4 lines
All bets are off if the local pathnames are required by the remote server. That is silly. How would a networked client even know what the pathname would be? The parameters should be the two file handles passed to the remote filesystem.
You may need a filename relative to the root of the exported part of the tree.
Remote side:
J:\groups\rteng\John Smith\tests\a.out (with rteng exported as \\RTENG)
Local side:/home/john/tests/a.out
(the mount point is "/home/john")
Path needed:
\\RTENG\John Smith\tests\a.out
You have that, since the kernel knows that a "\\\\RTENG\\John Smith" directory was mounted on /home/john and you're trying to deal with a tests/a.out file.
Quoted 4 lines
Personally, I don't think any changes should be made. It's just that this level of transfer is what the original poster was talking about. It just shouldn't be done in kernel mode.
Anywhere else would be buggy and most likely setuid.
Quoted 8 lines · Jesse Pollard
Quoted 4 lines
Quoted 1 line
int
sys_copy(int fd_src, int fd_dst)Doesn't work. You have to set the security attributes while you open
fd_dst.Why? the open for
fd_srcshould have the security attributes (both locally and in the file server if networked). Openingfd_dstshould SET the security attributes desired (again, locally and in the target fileserver).
The default attributes in the new location might be less strict than the attributes of the source file.
If sys_copy() is just an API to introduce a new copy-on-write hard link, these problems disappear. They are only relevant if sys_copy() is intended to be a generic "copy that file" interface.
Quoted 6 lines · Florian Weimer
Quoted 5 lines · Jesse Pollard
Quoted 4 lines
Quoted 1 line
int
sys_copy(int fd_src, int fd_dst)Doesn't work. You have to set the security attributes while you open
fd_dst.
Quoted 7 lines
Quoted 4 lines
Why? the open for
fd_srcshould have the security attributes (both locally and in the file server if networked). Openingfd_dstshould SET the security attributes desired (again, locally and in the target fileserver).The default attributes in the new location might be less strict than the attributes of the source file.
So what. the user was authorized to open the input file. The user was authorized to open the output file. A file copy should be possible remotely since the equivalent implementation of a local read/write loop would accomplish the same thing.
Quoted 3 lines
If
sys_copy()is just an API to introduce a new copy-on-write hard link, these problems disappear. They are only relevant ifsys_copy()is intended to be a generic "copy that file" interface.
Now if you wanted the remote server to deny the network copy... could be done - after all the credentials for both input and output files are present on the server. If the server decides NOT to copy, then fine. It would just cause the user to make the copy with a read/write loop.
I was only thinking of it as a way to gain access to any filesystem support that may be available for copying files. If none is available, then do it in user mode.
Personally, I'm not sure it is a good idea, partly because the semantics of a file copy operation are not well defined (some of the following IS known).
1. what happens if the copy is aborted?
2. what happens if the network drops while the remote server continues?
3. what about buffer synchronization?
4. what errors should be reported ?
5. what happens when the syscall is interupted? Especially if the remote copy may take a while (I've seen some require an hour or more - worst
case: days due to a media error (completed after the disk was replaced)).
6. what about a client opening the copy before it is finished copying?
Quoted 9 lines · Jesse Pollard
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
int
sys_copy(int fd_src, int fd_dst)The default attributes in the new location might be less strict than the attributes of the source file.
So what. the user was authorized to open the input file. The user was authorized to open the output file. A file copy should be possible remotely since the equivalent implementation of a local read/write loop would accomplish the same thing.
The potential for race conditions worries me. However, the questions you gave are more fundamental and may be enough to kill this idea (if it wasn't already dead)...
Quoted 13 lines · Jesse Pollard
Now if you wanted the remote server to deny the network copy... could be done - after all the credentials for both input and output files are present on the server. If the server decides NOT to copy, then fine. It would just cause the user to make the copy with a read/write loop.
I was only thinking of it as a way to gain access to any filesystem support that may be available for copying files. If none is available, then do it in user mode.
Personally, I'm not sure it is a good idea, partly because the semantics of a file copy operation are not well defined (some of the following IS known).
Quoted 8 lines
1. what happens if the copy is aborted?
2. what happens if the network drops while the remote server continues?
3. what about buffer synchronization?
4. what errors should be reported ?
5. what happens when the syscall is interupted? Especially if the remote copy may take a while (I've seen some require an hour or more - worst
case: days due to a media error (completed after the disk was replaced)).
6. what about a client opening the copy before it is finished copying?
If you really want a filesystem that supports efficient copying you probably want it to have the equivalent of COW blocks, so that a copy just sets up a few pointers, and the copy only happens when the original or copied files are changed.
But basically you wont get a syscall until you have a filesystem with semantics that only maps onto this sort of operation.
Justin
Quoted 9 lines · Justin Cormack
On Thu, 2003-11-20 at 19:08, Jesse Pollard wrote:
If you really want a filesystem that supports efficient copying you probably want it to have the equivalent of COW blocks, so that a copy just sets up a few pointers, and the copy only happens when the original or copied files are changed.
But basically you wont get a syscall until you have a filesystem with semantics that only maps onto this sort of operation.
This could be a problem if COW causes you to run out of space when writing to the file.
This could also be a benefit if, for whatever reason, you have lots of copies of the same file that you never change. But that sounds somewhat pointless to me.
Quoted 2 lines · Timothy Miller
This could be a problem if COW causes you to run out of space when writing to the file.
Not much different than running out of space copying a file.
Quoted 3 lines
This could also be a benefit if, for whatever reason, you have lots of copies of the same file that you never change. But that sounds somewhat pointless to me.
Umm, snapshots-in-time of your /home, /usr/src, etc? Copies of the kernel? Lots of reasons to have mostly-identical versions of files. Almost like hard links, except you aren't at the mercy of your editor/patch to do the right thing when modifying one of those copies.
Cheers, Andreas
--
Andreas Dilger
http://sourceforge.net/projects/ext2resize/
http://www-mddsp.enel.ucalgary.ca/People/adilger/
Quoted 6 lines · Andreas Dilger
Quoted 1 line · Timothy Miller
This could be a problem if COW causes you to run out of space when writing to the file.
Not much different than running out of space copying a file.
It is, though. If you run out of space copying a file, you know it when you're copying. Applications don't usually expect to get out-of-space errors while overwriting something in the middle of a file.
In effect, your free space and your used space add up to greater than the capacity of the disk. An application that checks for free space before doing something would be fooled into thinking there is more free space than there really is. How can an application find out in advance that a file that it's about to modify (without appending anything to the end) is going to need more disk space?
Assume 'fast'copy(int fd_in, int fd_out) where fd_in and fd_out reference files. fd_in is opened for read and fd_out is opened for write. Ignore filepos locations in both fd's. fd_out must reference an empty/truncated file (if not then fail). Usually you'd call copy on fd_out straight out of a creat call (and thus this would be a non-issue).
Quoted 1 line
1. what happens if the copy is aborted?
I'd say the copy operation should be 'atomic', either it succeeds (full copy) or fails (no changes to filesystems except for the truncate). An abort would obviously usually result in a failure (thus a possible revert, which is rather easy since it's likely just an truncate of whatever has already been copied) or if we've just finished and than a successful result.
Quoted 1 line
2. what happens if the network drops while the remote server continues?
If the remote server has enough data to perform the operation then it does complete it otherwise there ain't enough info anyway (afterall the entire idea of this is to fit the entire copy into a single copy instruction thus a single packet/command whatever, no extra data is passed)...
Quoted 1 line
3. what about buffer synchronization?
If this is happening remotely then I don't see what requires sync???
Quoted 1 line
4. what errors should be reported ?
This is tougher:
Tests first performed locally (if they can be) than request forwarded to remote end and tests performed remotely - return either error or ACCEPTED, at which point local end tells it to go ahead, (at this point the operation is effectively performed (unless an abort is signalled) regardless of network connectivity). On completion remote end will return info on completion or error code.
a) operation not supported by kernel :) - ENOSYS
b) fd_in/fd_out invalid file descriptor - EBADF
c) fd_in/fd_out is directory - EISDIR
d) can't read/write from/to fd_in/fd_out - EINVAL
e) an error if fd_out ain't empty - ENOTEMPTY
f) operation not supported by this combination of devices - EOPNOTSUPP [so you need to do it via usual loop]
g) input file bigger then output file can be - EFBIG
[ie copy of 5GB file from remote filesystem which supports it to another filesystem on the same server with 2GB max file size]
h) low-level IO error - EIO - serious problems (i.e. HDD read/write error)
i) out of disk space during copy - ENOSPC
j) out of memory during copy - ENOMEM (unlikely, needed?)
k) lost network connection - ENETRESET (unknown whether succeeded) or ENOLINK ?
l) operation was aborted - EINTR [probably should be some other error code, not sure]
m) success - either return 0 or the number of bytes copied [probably best to return the # of bytes copied, even if (for now?) we only accept full copies]
Did I miss anything? What about non-blocking call? Basically as above but return INPROGRESS as soon as we tell remote end to go ahead... or perhaps don't support non-blocking call?
Quoted 3 lines
5. what happens when the syscall is interupted? Especially if the remote copy may take a while (I've seen some require an hour or more - worst
case: days due to a media error (completed after the disk was replaced)).
Well, if it's interrupted by a SIGINT or the like then return EINTR and the copy was not performed (ie we backed the copy out, unless net failure detected during abort then ENOLINK/ENETRESET).
If it's a more normal signal than it should behave like any normal kernel restartable syscall (i.e. via ERESTARTNOHAND or something like that).
Quoted 1 line
6. what about a client opening the copy before it is finished copying?
The file copy is atomic and thus the file doesn't per se exist until the copy operation completes (or the file exists with zero size and is locked and can't be opened).
Perhaps in the future we could support partial copies and restarting an interrupted copy, but let's first agree (or not) on the above.
I think a copy syscall would be very useful. What I'd really like to see is some sort of block-hashed-space-compression with copy-on-write semantics file system for linux (for my 500 CD collection which probably has a 10-12 data duplicity factor).
Comments?
Cheers,
MaZe.
Quoted 3 lines
It is, though. If you run out of space copying a file, you know it when you're copying. Applications don't usually expect to get out-of-space errors while overwriting something in the middle of a file.
What about sparse files?
Quoted 6 lines
In effect, your free space and your used space add up to greater than the capacity of the disk. An application that checks for free space before doing something would be fooled into thinking there is more free space than there really is. How can an application find out in advance that a file that it's about to modify (without appending anything to the end) is going to need more disk space?
I don't think it can do that already now with sparse files, can it?
Cheers,
MaZe.
Quoted 4 lines · Maciej Zenczykowski
Quoted 1 line
It is, though. If you run out of space copying a file, you know it when you're copying. Applications don't usually expect to get out-of-space errors while overwriting something in the middle of a file.
What about sparse files?
Ah, good point. Never mind. :)
Quoted 7 lines
Quoted 6 lines · Andreas Dilger
Quoted 2 lines · Timothy Miller
This could be a problem if COW causes you to run out of space when writing to the file.
Quoted 6 lines
Quoted 1 line
Not much different than running out of space copying a file.
It is, though. If you run out of space copying a file, you know it when you're copying. Applications don't usually expect to get
out-of-space errors while overwriting something in the middle of a
file.
It could for journaling filesystem already.
It's not in any spec that writing to the middle of a file would not cause ENOSPC, is it?
Quoted 7 lines
In effect, your free space and your used space add up to greater than the capacity of the disk. An application that checks for free space before doing something would be fooled into thinking there is more free space than there really is. How can an application find out
in advance that a file that it's about to modify (without appending anything to the end) is going to need more disk space?
Quoted 8 lines · Jesse Pollard
1. what happens if the copy is aborted?
2. what happens if the network drops while the remote server continues?
3. what about buffer synchronization?
4. what errors should be reported ?
5. what happens when the syscall is interupted? Especially if the remote copy may take a while (I've seen some require an hour or more - worst
case: days due to a media error (completed after the disk was replaced)).
6. what about a client opening the copy before it is finished copying?
7. How to report progress with your average file manager ?
Quoted 2 lines · Xavier Bestel
Quoted 1 line · Jesse Pollard
1. what happens if the copy is aborted?
Same as now with "cp" - partial copy.
Quoted 1 line
Quoted 1 line
2. what happens if the network drops while the remote server continues?
Irrelevant, since you can't access the file at that point (i.e. if server continues then great, but if it doesn't it's no different than the server disconnecting/crashing in the middle of a regular copy.
Quoted 1 line
Quoted 1 line
3. what about buffer synchronization?
Sync file locally before starting, and no buffers on client are created. If you write to file while it is being copied, how is that different than two writers for same file now (i.e. usually broken). If the network filesystem doesn't support locking, that's the filesystem's problem and this API doesn't change it.
Quoted 1 line
Quoted 1 line
4. what errors should be reported ?
Covered pretty well elsewhere. Of course EINTR should be reserved for "interrupted, please continue if you want" as opposed to a hard error.
Quoted 3 lines
Quoted 3 lines
5. what happens when the syscall is interupted? Especially if the remote copy may take a while (I've seen some require an hour or more - worst
case: days due to a media error (completed after the disk was replaced)).
Partial copy, no different than now.
Quoted 1 line
Quoted 1 line
6. what about a client opening the copy before it is finished copying?
Reads partial file, no different than now.
Quoted 1 line
7. How to report progress with your average file manager ?
Support signals and restart the copy where it left off. Interrupting once a second or whatever isn't onerous if needed and you can restart. You could even support some sort of "SIGUSR1" like dd does to get status back without actually killing things. Alternately, just stat the target file as it is being copied to watch progress.
Cheers, Andreas
--
Andreas Dilger
http://sourceforge.net/projects/ext2resize/
http://www-mddsp.enel.ucalgary.ca/People/adilger/
Quoted 1 line · Justin Cormack
On Thu, 2003-11-20 at 19:08, Jesse Pollard wrote:
[snip]
Quoted 5 lines
If you really want a filesystem that supports efficient copying you probably want it to have the equivalent of COW blocks, so that a copy just sets up a few pointers, and the copy only happens when the original or copied files are changed.
Ummmm... I REALLY don't like COW on a disk. Much too big a chance that the filesystem will deadlock, and with no recovery method. (oversubscribed, then crash, corrupting the homeblock, repair (committing journal?) requires space... no space... therefore mostly dead. You'd have to be able to mount without the journal or the homeblock, then delete something, then commit the journal, dismount, recover the rest-- though this might be overboard, the homebock might not even be damaged).
Quoted 2 lines
But basically you wont get a syscall until you have a filesystem with semantics that only maps onto this sort of operation.
I belive NFSv3/4 has a file copy request included. And I understand that the SAMBA server does too.
Quoted 6 lines · Maciej Zenczykowski
Assume 'fast'copy(int
fd_in, intfd_out) wherefd_inandfd_outreference files.fd_inis opened for read andfd_outis opened for write. Ignore filepos locations in both fd's.fd_outmust reference an empty/truncated file (if not then fail). Usually you'd call copy onfd_outstraight out of a creat call (and thus this would be a non-issue).
Quoted 8 lines
Quoted 1 line
1. what happens if the copy is aborted?
I'd say the copy operation should be 'atomic', either it succeeds (full copy) or fails (no changes to filesystems except for the truncate). An abort would obviously usually result in a failure (thus a possible revert, which is rather easy since it's likely just an truncate of whatever has already been copied) or if we've just finished and than a successful result.
Really? what happens if the abort is local to the system making the request? what happens if the abort is on the remote server?
Quoted 7 lines
Quoted 1 line
2. what happens if the network drops while the remote server continues?
If the remote server has enough data to perform the operation then it does complete it otherwise there ain't enough info anyway (afterall the entire idea of this is to fit the entire copy into a single copy instruction thus a single packet/command whatever, no extra data is passed)...
And back to aborts?
Quoted 3 lines
Quoted 1 line
3. what about buffer synchronization?
If this is happening remotely then I don't see what requires sync???
Multiple hosts remote to the server that have afile open. Though this already happens with NFS.
Quoted 36 lines
Quoted 1 line
4. what errors should be reported ?
This is tougher:
Tests first performed locally (if they can be) than request forwarded to remote end and tests performed remotely - return either error or ACCEPTED, at which point local end tells it to go ahead, (at this point the operation is effectively performed (unless an abort is signalled) regardless of network connectivity). On completion remote end will return info on completion or error code.
a) operation not supported by kernel :) - ENOSYS
b) fd_in/fd_out invalid file descriptor - EBADF
c) fd_in/fd_out is directory - EISDIR
d) can't read/write from/to fd_in/fd_out - EINVAL
e) an error iffd_outain't empty - ENOTEMPTY
f) operation not supported by this combination of devices - EOPNOTSUPP [so you need to do it via usual loop]
g) input file bigger then output file can be - EFBIG
[ie copy of 5GB file from remote filesystem which supports it to another filesystem on the same server with 2GB max file size]
h) low-level IO error - EIO - serious problems (i.e. HDD read/write error)
i) out of disk space during copy - ENOSPC
j) out of memory during copy - ENOMEM (unlikely, needed?)
k) lost network connection - ENETRESET (unknown whether succeeded) or ENOLINK ?
l) operation was aborted - EINTR [probably should be some other error code, not sure]
m) success - either return 0 or the number of bytes copied [probably best to return the # of bytes copied, even if (for now?) we only accept full copies]Did I miss anything? What about non-blocking call? Basically as above but return INPROGRESS as soon as we tell remote end to go ahead... or perhaps don't support non-blocking call?
Quoted 8 lines
Quoted 4 lines
5. what happens when the syscall is interupted? Especially if the remote copy may take a while (I've seen some require an hour or more - worst
case: days due to a media error (completed after the disk was
replaced)).Well, if it's interrupted by a SIGINT or the like then return EINTR and the copy was not performed (ie we backed the copy out, unless net failure detected during abort then ENOLINK/ENETRESET).
Ooop - the copy is being done on the remote server.
Quoted 2 lines
If it's a more normal signal than it should behave like any normal kernel restartable syscall (i.e. via ERESTARTNOHAND or something like that).
Again, the copy may be being made on the remote server.
Quoted 5 lines
Quoted 1 line
6. what about a client opening the copy before it is finished copying?
The file copy is atomic and thus the file doesn't per se exist until the copy operation completes (or the file exists with zero size and is locked and can't be opened).
It does under all other methods of copying.
Quoted 7 lines
Perhaps in the future we could support partial copies and restarting an interrupted copy, but let's first agree (or not) on the above.
I think a copy syscall would be very useful. What I'd really like to see is some sort of block-hashed-space-compression with copy-on-write semantics file system for linux (for my 500 CD collection which probably has a 10-12 data duplicity factor).
It could be usefull. What you describe now is a migrating filesystem on a server. And note that your COW is going from two different filesystems (hmm or maybe a custom union mount?)...
Which is where the migrating filesystem. The served filesystem should already know how to transfer a file from the archive.
Hi!
Quoted 9 lines
Quoted 5 lines
Quoted 2 lines
This could be a problem if COW causes you to run out of space when writing to the file.
Not much different than running out of space copying a file.
It is, though. If you run out of space copying a file, you know it when you're copying. Applications don't usually expect to get out-of-space errors while overwriting something in the middle of a file.
Same can happen on compressed filesystem...
Pavel
Signature · 2 lines
When do you have a heart between your knees? [Johanka's followup: and *two* hearts?]
Quoted 5 lines · Pavel Machek
Quoted 3 lines
It is, though. If you run out of space copying a file, you know it when you're copying. Applications don't usually expect to get out-of-space errors while overwriting something in the middle of a file.
Same can happen on compressed filesystem...
Or a filesystem with snapshots, e.g. using LVM.
-- Jamie
Quoted 8 lines · Jamie Lokier
Quoted 5 lines · Pavel Machek
Quoted 3 lines
It is, though. If you run out of space copying a file, you know it when you're copying. Applications don't usually expect to get out-of-space errors while overwriting something in the middle of a file.
Same can happen on compressed filesystem...
Or a filesystem with snapshots, e.g. using LVM.
Or writing to a sparse file.
Andreas.
Signature · 4 lines
Andreas Schwab, SuSE Labs, [email protected] SuSE Linux AG, Deutschherrnstr. 15-19, D-90429 Nürnberg Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different."
(Among the other N objections, add things like the lack of any sort of control or option parameters)
...
N += 1: Sparse Copying (e.g. seeking past blocks of zeros)
N += 1: Unlink or overwrite or what?
N += 1: In-Kernel locking and resolution for pages that are mandatory lock(ed)
N += 1: No fine-grained control for concurrency issues (multiple writers)
Start with doing a cp --help and move on from there for an unbounded list of issues that sys_copy(int fd1, int fd2) does not even come close to addressing.
Quoted 9 lines · Robert White
(Among the other N objections, add things like the lack of any sort of control or option parameters)
...
N += 1: Sparse Copying (e.g. seeking past blocks of zeros)
N += 1: Unlink or overwrite or what?
N += 1: In-Kernel locking and resolution for pages that are mandatory lock(ed)
N += 1: No fine-grained control for concurrency issues (multiple writers)
Quoted 5 lines
Start with doing a cp --help and move on from there for an unbounded list of issues that
sys_copy(int fd1, int fd2)does not even come close to addressing.
To be fair, sys_copy is never intended to replace cp or try to be very smart. I don't think it is semantically supposed to do much more than replace a read, write loop (of course, the syscall also has an offset and count).
sparse copying would be implementation dependant. If cp wanted to do something special it would not use one big copy call. I think unlink / overwrite is irrelevant if its semantically a read write loop.
Quoted 17 lines · Nick Piggin
Quoted 9 lines · Robert White
(Among the other N objections, add things like the lack of any sort of control or option parameters)
...
N += 1: Sparse Copying (e.g. seeking past blocks of zeros)
N += 1: Unlink or overwrite or what?
N += 1: In-Kernel locking and resolution for pages that are mandatory lock(ed)
N += 1: No fine-grained control for concurrency issues (multiple writers)Quoted 5 lines
Start with doing a cp --help and move on from there for an unbounded list of issues that
sys_copy(int fd1, int fd2)does not even come close to addressing.
Quoted 9 lines
To be fair,
sys_copyis never intended to replace cp or try to be very smart. I don't think it is semantically supposed to do much more than replace a read, write loop (of course, the syscall also has an offset and count).sparse copying would be implementation dependant. If cp wanted to do something special it would not use one big copy call. I think unlink / overwrite is irrelevant if its semantically a read write loop.
actually if this syscall is allowed to do a COW at the filesystem level (which I think is one of the better reasons for implementing this) then sparse files would produce sparse copies.
if the destination exists it would need to be unlinked (overwrite doesn't make sense in the COW context)
I don't understand the in-kernel page locking issues refered to above
the concurrancy issues are a good question, but I would suggest that the syscall fully setup the copy and then create the link to it. this would make the final creation an atomic operation (or as close to it as a particular filesystem allows) and if you have multiple writers doing a copy to the same destination then the last one wins, the earlier copies get unlinked and deleted
I definantly don't see it being worth it to make a syscall to just implement the read/write loop, but a copy syscall designed from the outset to do a COW copy that falls back to a read/write loop for filesystems that don't do COW has some real benifits
David Lang
Signature · 3 lines
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." - Brian W. Kernighan
Quoted 32 lines · David Lang
Quoted 18 lines · Nick Piggin
Quoted 9 lines · Robert White
(Among the other N objections, add things like the lack of any sort of control or option parameters)
...
N += 1: Sparse Copying (e.g. seeking past blocks of zeros)
N += 1: Unlink or overwrite or what?
N += 1: In-Kernel locking and resolution for pages that are mandatory lock(ed)
N += 1: No fine-grained control for concurrency issues (multiple writers)Quoted 6 lines
Start with doing a cp --help and move on from there for an unbounded list of issues that
sys_copy(int fd1, int fd2)does not even come close to addressing.Quoted 10 lines
To be fair,
sys_copyis never intended to replace cp or try to be very smart. I don't think it is semantically supposed to do much more than replace a read, write loop (of course, the syscall also has an offset and count).sparse copying would be implementation dependant. If cp wanted to do something special it would not use one big copy call. I think unlink / overwrite is irrelevant if its semantically a read write loop.
Quoted 4 lines
actually if this syscall is allowed to do a COW at the filesystem level (which I think is one of the better reasons for implementing this) then sparse files would produce sparse copies.
Sure, I just mean the semantics should be equivalent to a read write loop. Another example is zero copy copy for a remote fs that supports it.
Quoted 4 lines
if the destination exists it would need to be unlinked (overwrite doesn't make sense in the COW context)
Well it would be implementation specific. Presumably it should keep the semantics of an overwrite.
Quoted 10 lines
I don't understand the in-kernel page locking issues refered to above
the concurrancy issues are a good question, but I would suggest that the syscall fully setup the copy and then create the link to it. this would make the final creation an atomic operation (or as close to it as a particular filesystem allows) and if you have multiple writers doing a copy to the same destination then the last one wins, the earlier copies get unlinked and deleted
I don't think it should do any linking / unlinking it should just work with file descriptors. Concurrent writes to a file don't have many guarantees. sys_copy shouldn't have to be any stronger (read weaker).
Quoted 6 lines
I definantly don't see it being worth it to make a syscall to just implement the read/write loop, but a copy syscall designed from the outset to do a COW copy that falls back to a read/write loop for filesystems that don't do COW has some real benifits
No I just mean the semantics.
Quoted 19 lines · Nick Piggin
Quoted 4 lines
if the destination exists it would need to be unlinked (overwrite doesn't make sense in the COW context)
Well it would be implementation specific. Presumably it should keep the semantics of an overwrite.
Quoted 10 lines
I don't understand the in-kernel page locking issues refered to above
the concurrancy issues are a good question, but I would suggest that the syscall fully setup the copy and then create the link to it. this would make the final creation an atomic operation (or as close to it as a particular filesystem allows) and if you have multiple writers doing a copy to the same destination then the last one wins, the earlier copies get unlinked and deleted
Quoted 3 lines
I don't think it should do any linking / unlinking it should just work with file descriptors. Concurrent writes to a file don't have many guarantees.
sys_copyshouldn't have to be any stronger (read weaker).
I'm thinking that it may actually be easier to do this via file paths instead of file descripters. with file paths something like COW or zero-copy copy can be done trivially (and the kernel knows the user credentials of the program issuing the command and can pass them on to the filesystem to see if it's allowed). I don't see how this can be done with file descripters (if all you have is a file descripter you can truncate and write a file, but you don't know all the links to that file so you can't reposition that first inode for example).
Quoted 11 lines
Quoted 6 lines
I definantly don't see it being worth it to make a syscall to just implement the read/write loop, but a copy syscall designed from the outset to do a COW copy that falls back to a read/write loop for filesystems that don't do COW has some real benifits
No I just mean the semantics.
Signature · 3 lines
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." - Brian W. Kernighan
Quoted 5 lines · David Lang
Quoted 4 lines
I don't think it should do any linking / unlinking it should just work with file descriptors. Concurrent writes to a file don't have many guarantees.
sys_copyshouldn't have to be any stronger (read weaker).
Quoted 8 lines
I'm thinking that it may actually be easier to do this via file paths instead of file descripters. with file paths something like COW or zero-copy copy can be done trivially (and the kernel knows the user credentials of the program issuing the command and can pass them on to the filesystem to see if it's allowed). I don't see how this can be done with file descripters (if all you have is a file descripter you can truncate and write a file, but you don't know all the links to that file so you can't reposition that first inode for example).
And how is userspace supposed to protect itself from race conditions? Just compare:
fd1 = open(path1);
if (stat(fd1) looks fishy)
abort(); fd2 = open(path2); if (stat(fd2) looks fishy) abort();
copy(fd1, fd2);
and:
fd1 = open(path1);
if (stat(fd1) looks fishy)
abort(); fd2 = open(path2); if (stat(fd2) looks fishy) abort();
copy(path1, path2);
Jörn
Signature · 4 lines
Don't worry about people stealing your ideas. If your ideas are any good, you'll have to ram them down people's throats. -- Howard Aiken quoted by Ken Iverson quoted by Jim Horning quoted by Raph Levien, 1979
Quoted 30 lines · Jörn Engel
Quoted 5 lines · David Lang
Quoted 4 lines
I don't think it should do any linking / unlinking it should just work with file descriptors. Concurrent writes to a file don't have many guarantees.
sys_copyshouldn't have to be any stronger (read weaker).Quoted 8 lines
I'm thinking that it may actually be easier to do this via file paths instead of file descripters. with file paths something like COW or zero-copy copy can be done trivially (and the kernel knows the user credentials of the program issuing the command and can pass them on to the filesystem to see if it's allowed). I don't see how this can be done with file descripters (if all you have is a file descripter you can truncate and write a file, but you don't know all the links to that file so you can't reposition that first inode for example).
And how is userspace supposed to protect itself from race conditions? Just compare:
fd1 = open(path1);
if (stat(fd1) looks fishy)abort(); fd2 = open(path2); if (stat(fd2) looks fishy) abort();
copy(fd1, fd2);and:
fd1 = open(path1);
if (stat(fd1) looks fishy)
Quoted 8 lines
abort(); fd2 = open(path2); if (stat(fd2) looks fishy) abort();
copy(path1, path2);Jörn
Ok, good point. my first reaction is to make copy refuse to function unless the target doesn't exist (protect the output), but that doesn't solve the problem of protecting the input or preventing someone else from tampering with the output (unless you have copy return the FD to use to access the output)
actually thinking about it a bit more, did I make a stupid mistake and think that the FD points at the beginning of the file when it really points at the inode? if it points at the inode then the problems I was refering to don't exist.
David Lang
On Thursday 27 November 2003 04:58, David Lang wrote:
[snip]
Quoted 4 lines
actually thinking about it a bit more, did I make a stupid mistake and think that the FD points at the beginning of the file when it really points at the inode? if it points at the inode then the problems I was refering to don't exist.
Actually, it points to inode and offset in the file. The advantage this has is in the case of appending to a file... open the destination file, seek to the end, then copy. It also allows seeking some offset in the input file, then copying the rest of the file.