linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
[parent not found: <1068512710.722.161.camel@cube.suse.lists.linux.kernel>]
[parent not found: <Qvw7.5Qf.9@gated-at.bofh.it>]
[parent not found: <QDtX.2dq.15@gated-at.bofh.it>]
* Re: OT: why no file copy() libc/syscall ??
@ 2003-11-11  1:05 Albert Cahalan
  2003-11-11  3:50 ` Andreas Dilger
                   ` (2 more replies)
  0 siblings, 3 replies; 77+ messages in thread
From: Albert Cahalan @ 2003-11-11  1:05 UTC (permalink / raw)
  To: linux-kernel mailing list
  Cc: davide.rossetti, filia, jesse, dwmw2, moje, kakadu_croc

> 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.

> 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)

> 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

> 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.

> 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.

>> 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.

> 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.

> 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.

> 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.
>
> 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.



^ permalink raw reply	[flat|nested] 77+ messages in thread
* Re: OT: why no file copy() libc/syscall ??
@ 2003-11-10 12:09 Bradley Chapman
  2003-11-10 18:47 ` Tomas Konir
  2003-11-10 22:44 ` Derek Foreman
  0 siblings, 2 replies; 77+ messages in thread
From: Bradley Chapman @ 2003-11-10 12:09 UTC (permalink / raw)
  To: davide.rossetti; +Cc: linux-kernel

Mr. Rossetti,

It is horribly RTFM.

man 2 sendfile is what you're after.

Brad

=====
Brad Chapman

Permanent e-mail: kakadu_croc@yahoo.com

__________________________________
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
http://antispam.yahoo.com/whatsnewfree

^ permalink raw reply	[flat|nested] 77+ messages in thread
* OT: why no file copy() libc/syscall ??
@ 2003-11-10 11:33 Davide Rossetti
  0 siblings, 0 replies; 77+ messages in thread
From: Davide Rossetti @ 2003-11-10 11:33 UTC (permalink / raw)
  To: linux-kernel

it may be orribly RTFM... but writing a simple framework I realized 
there is no libc/POSIX/whoknows
copy(const char* dest_file_name, const char* src_file_name)

What is the technical reason???

I understand that there may be little space for kernel side 
optimizations in this area but anyway I'm surprised I have to write

< the bits to clone the metadata of src_file_name on opening 
dest_file_name >
const int BUFSIZE = 1<<12;
char buffer[BUFSIZE];
int nrb;
while((nrb = read(infd, buffer, BUFSIZE) != -1) {
  ret = write(outfd, buffer, nrb);
  if(ret != nrb) {...}
}

instead of something similar to:
sys_fscopy(...)

regards




^ permalink raw reply	[flat|nested] 77+ messages in thread

end of thread, other threads:[~2003-12-01 16:36 UTC | newest]

Thread overview: 77+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <QiyV.1k3.15@gated-at.bofh.it>
2003-11-10 12:08 ` OT: why no file copy() libc/syscall ?? Ihar 'Philips' Filipau
2003-11-10 13:29   ` Jesse Pollard
2003-11-10 14:22     ` Daniel Jacobowitz
2003-11-11 20:57       ` Jakob Oestergaard
2003-11-10 15:19     ` David Woodhouse
2003-11-10 16:15       ` Jesse Pollard
2003-11-11 12:00     ` davide.rossetti
2003-11-11 12:08       ` Andreas Schwab
2003-11-11 12:23         ` davide.rossetti
     [not found] <1068512710.722.161.camel@cube.suse.lists.linux.kernel>
     [not found] ` <20031111133859.GA11115@bitwizard.nl.suse.lists.linux.kernel>
     [not found]   ` <20031111085323.M8854@devserv.devel.redhat.com.suse.lists.linux.kernel>
     [not found]     ` <bp0p5m$lke$1@cesium.transmeta.com.suse.lists.linux.kernel>
     [not found]       ` <20031113233915.GO1649@x30.random.suse.lists.linux.kernel>
     [not found]         ` <3FB4238A.40605@zytor.com.suse.lists.linux.kernel>
     [not found]           ` <20031114011009.GP1649@x30.random.suse.lists.linux.kernel>
     [not found]             ` <3FB42CC4.9030009@zytor.com.suse.lists.linux.kernel>
2003-11-14 15:26               ` Andi Kleen
2003-11-18 15:49                 ` Jamie Lokier
2003-11-18 16:05                   ` Andi Kleen
2003-11-18 16:25                     ` Trond Myklebust
2003-11-19 13:30                   ` Jesse Pollard
2003-11-18 16:58                 ` H. Peter Anvin
2003-11-19  2:12                 ` Linus Torvalds
2003-11-19  4:04                 ` Chris Adams
     [not found] <Qvw7.5Qf.9@gated-at.bofh.it>
     [not found] ` <QxRl.17Y.9@gated-at.bofh.it>
     [not found]   ` <Qy0W.1sk.9@gated-at.bofh.it>
     [not found]     ` <QyaB.1GK.17@gated-at.bofh.it>
     [not found]       ` <QzSZ.4x1.1@gated-at.bofh.it>
     [not found]         ` <QCHh.X6.3@gated-at.bofh.it>
2003-11-11  9:51           ` Ihar 'Philips' Filipau
2003-11-11 10:41             ` jw schultz
     [not found] ` <QH4e.eV.3@gated-at.bofh.it>
2003-11-11 14:11   ` Ihar 'Philips' Filipau
2003-11-11 15:02     ` Rogier Wolff
2003-11-11 15:31       ` Ihar 'Philips' Filipau
2003-11-11 20:22       ` Jan Harkes
2003-11-11 20:31         ` Valdis.Kletnieks
     [not found] <QDtX.2dq.15@gated-at.bofh.it>
     [not found] ` <QDtX.2dq.17@gated-at.bofh.it>
     [not found]   ` <QDtX.2dq.19@gated-at.bofh.it>
     [not found]     ` <QDtX.2dq.21@gated-at.bofh.it>
     [not found]       ` <QDtX.2dq.23@gated-at.bofh.it>
     [not found]         ` <QDtY.2dq.25@gated-at.bofh.it>
     [not found]           ` <QDtX.2dq.13@gated-at.bofh.it>
     [not found]             ` <QEg2.3zi.9@gated-at.bofh.it>
2003-11-11 12:43               ` Ihar 'Philips' Filipau
2003-11-11  1:05 Albert Cahalan
2003-11-11  3:50 ` Andreas Dilger
2003-11-11  4:03   ` Daniel Gryniewicz
2003-11-11  4:14     ` Valdis.Kletnieks
2003-11-11  6:00       ` Andreas Dilger
2003-11-11  8:58         ` Florian Weimer
2003-11-11 10:27           ` jw schultz
2003-11-11 20:08             ` Jan Harkes
2003-11-12 15:36           ` Jesse Pollard
2003-11-20 17:21             ` Florian Weimer
2003-11-20 19:08               ` Jesse Pollard
2003-11-20 19:12                 ` Florian Weimer
2003-11-20 19:44                 ` Justin Cormack
2003-11-20 20:44                   ` Timothy Miller
2003-11-20 21:07                     ` Andreas Dilger
2003-11-20 21:30                       ` Timothy Miller
2003-11-20 21:49                         ` Maciej Zenczykowski
2003-11-20 21:52                           ` Timothy Miller
2003-11-20 21:58                         ` Hua Zhong
2003-11-22 14:50                         ` Pavel Machek
2003-11-22 19:50                           ` Jamie Lokier
2003-11-22 23:07                             ` Andreas Schwab
2003-11-21 16:24                   ` Jesse Pollard
2003-11-20 21:48                 ` Maciej Zenczykowski
2003-11-21 16:34                   ` Jesse Pollard
2003-11-20 22:31                 ` Xavier Bestel
2003-11-20 22:44                   ` Andreas Dilger
2003-11-27  2:40                 ` Robert White
2003-11-27  7:29                   ` Nick Piggin
2003-11-27  9:15                     ` David Lang
2003-11-27  8:56                       ` Nick Piggin
2003-11-27  9:50                         ` David Lang
2003-11-27 10:02                           ` Jörn Engel
2003-11-27 10:58                             ` David Lang
2003-12-01 16:20                               ` Jesse Pollard
2003-11-11  8:52   ` Gábor Lénárt
2003-11-11 13:38 ` Rogier Wolff
2003-11-11 13:53   ` Jakub Jelinek
2003-11-11 13:58     ` David Woodhouse
2003-11-13 20:22     ` H. Peter Anvin
2003-11-13 23:39       ` Andrea Arcangeli
2003-11-14  0:04         ` jw schultz
2003-11-14  0:36         ` H. Peter Anvin
2003-11-14  1:10           ` Andrea Arcangeli
2003-11-14  1:15             ` H. Peter Anvin
2003-11-11 14:11   ` Albert Cahalan
2003-11-12 15:19 ` Jesse Pollard
2003-11-14  3:42   ` Albert Cahalan
  -- strict thread matches above, loose matches on Subject: below --
2003-11-10 12:09 Bradley Chapman
2003-11-10 18:47 ` Tomas Konir
2003-11-10 22:44 ` Derek Foreman
2003-11-10 11:33 Davide Rossetti

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).