glusterfs icon indicating copy to clipboard operation
glusterfs copied to clipboard

copy_file_range support in Gluster

Open raghavendrabhat opened this issue 8 years ago • 23 comments

copy_file_range (or reflink) support in Gluster.

Now that, fuse has the support for copy_file_range call, it would be better to have that support built within Gluster as well. As mentioned in the issue 349 by nixpanic, copy_file_range would still be useful in situations where both the source and destination file are on the same brick. It could be consumed by efforts such as kubevirt to have clones of the images that would be saved in the Gluster volume.

Following changes would be necessary for supporting copy_file_range.

  • Changes in fuse xlator to receive the incoming copy_file_range fops from the kernel and then send the response of the fop back.

  • Changes in DHT to support the fop. Mainly, it has to check whether the two files are part of the same brick or not. If they belong to separate bricks, then DHT has to read the contents from the source file and write them to the destination file.

  • Changes in AFR to take proper locks on both the files and perform the operation.

  • Changes in EC for taking proper locks on the files concerned.

  • Changes in Sharding to be able to read the content from the correct shards and write them to the destination shards accordingly.

  • Changes in protocol/client and protocol/server for doing copy_file_range

  • Changes in changelog to record the operation (in the brick which has the destination file)

  • Changes in bitrot-stub to sign the file that is being written to (i.e. the destination file)

  • Changes in posix to perform the copy_file_range on the disk filesystem if the source and destination files happen to be present on the same brick.

  • Changes in iostats to be able to track the fop and its performance for profiling.

  • There might not be any extra changes needed in the performance xlators as the copy_file_range will be either performed by posix in the brick or DHT in the client. Both of the xlators sit below the performance xlators in the stack.

  • Changes in other core areas such as call-stub, defaults where copy_file_range fop has to be added.

raghavendrabhat avatar Oct 31 '18 01:10 raghavendrabhat

It'd be great to POC this first and actually see the improvement first. In QEMU, for example, they've added it, and it was disabled by default as under some circumstances, it did not perform better.

mykaul avatar Oct 31 '18 06:10 mykaul

Have a look at how NFSv4.2 specifies server-side-copy. This is what the NFS-client calls when something asks it to do copy_file_range().

nixpanic avatar Oct 31 '18 10:10 nixpanic

A patch https://review.gluster.org/21631 has been posted that references this issue.

copy_file_range support in GlusterFS

  • Changes in default to add copy_file_range support

  • Changes in call stub

  • New fop added.

  • Changes in syncop, syscall and other libglusterfs components

Change-Id: I280069c814dd21ce6ec3be00a884fc24ab692367 updates: #536 Signed-off-by: Raghavendra Bhat [email protected]

gluster-ant avatar Nov 13 '18 04:11 gluster-ant

A patch https://review.gluster.org/21633 has been posted that references this issue.

posix changes

  • New fop copy_file_range added to run that fop on the backend and send the response back

Change-Id: I974cf3a5112a0fce252fc0a93f8f86daf89d6d0e updates: #536 Signed-off-by: Raghavendra Bhat [email protected]

gluster-ant avatar Nov 13 '18 04:11 gluster-ant

A patch https://review.gluster.org/21635 has been posted that references this issue.

api changes

  • Added new API called glfs_copy_file_range

Change-Id: I5668a6ea7ad032eb3efc457c32799987aa2e652f updates: #536 Signed-off-by: Raghavendra Bhat [email protected]

gluster-ant avatar Nov 13 '18 04:11 gluster-ant

The document [1] contains a write up about copy_file_range.

[1] https://docs.google.com/document/d/1BSILbXr_knynNwxSyyu503JoTz5QFM_4suNIh2WwrSc/edit

raghavendrabhat avatar Nov 18 '18 17:11 raghavendrabhat

A patch https://review.gluster.org/21682 has been posted that references this issue.

io-stats: capture copy_file_range fop for profile info

Change-Id: I33916cf334951af689239d92d055c62d3bd4c92b updates: #536 Signed-off-by: Raghavendra Bhat [email protected]

gluster-ant avatar Nov 20 '18 04:11 gluster-ant

Patch is failing in the smoke test for freebsd. It is because, freebsd is not able to recognize the data type loff_t. But that data type is what copy_file_range manpage says the offsets of the source and destination file will be of. I added the following changes in linglusterfs/src/glusterfs/compat.h

#if !defined(GF_LINUX_HOST_OS) typedef off_t loff_t #endif

But even after that, the freebsd is complaining with the following error.

17:37:24 In file included from /usr/home/jenkins/root/workspace/freebsd-smoke/libglusterfs/src/logging.c:29:0: 17:37:24 /usr/home/jenkins/root/workspace/freebsd-smoke/libglusterfs/src/glusterfs/syscall.h:232:32: error: unknown type name 'loff_t' 17:37:24 sys_copy_file_range(int fd_in, loff_t *off_in, int fd_out, loff_t *off_out, 17:37:24 ^~~~~~ 17:37:24 /usr/home/jenkins/root/workspace/freebsd-smoke/libglusterfs/src/glusterfs/syscall.h:232:60: error: unknown type name 'loff_t' 17:37:24 sys_copy_file_range(int fd_in, loff_t *off_in, int fd_out, loff_t *off_out, 17:37:24 ^~~~~~

Any idea how to handle the loff_t data type in freebsd?

@pranithk @amarts @nixpanic @kotreshhr please let me know how this can be handled. Does this mean, copy_file_range fop in entire gluster stack should be handled with the check "#ifdef GF_LINUX_HOST_OS" ?

raghavendrabhat avatar Dec 07 '18 00:12 raghavendrabhat

Does FreeBSD have copy_file_range or similar functionality at all? I think it is OK to return ENOSYS or something on environments where there is no support for it.

nixpanic avatar Dec 07 '18 10:12 nixpanic

FreeBSD does not have copy_file_range(2). (Doesn't look like it's getting it in FreeBSD 12 either.)

One solution would be to move the

#if !defined(GF_LINUX_HOST_OS) typedef off_t loff_t #endif

to libglusterfs/src/syscall.h, immediatedly before the decl of sys_copy_file_range().

Or....

While the man copy_file_range(2) man page says it's loff_t, the decl in <unistd.h> says it's __off64_t.

But since the offset parameters are actually pointers I think it's not worth getting bogged down in this. I'd just change the loff_t to off64_t, which both *BSD and Linux have, and be done.

Whichever way you do it, use off64_t (not off_t) so that it's a pointer-to-64-bit type on 32-bit platforms too.

kalebskeithley avatar Dec 07 '18 14:12 kalebskeithley

On Fri, Dec 7, 2018 at 9:19 AM kalebskeithley [email protected] wrote:

FreeBSD does not have copy_file_range(2). (Doesn't look like it's getting it in FreeBSD 12 either.)

One solution would be to move the

#if !defined(GF_LINUX_HOST_OS) typedef off_t loff_t #endif

Hmm. In fact I tried the exact above method. But it led to other compilation failures like below.

10:40:22 from /usr/home/jenkins/root/workspace/freebsd-smoke/rpc/rpc-lib/src/rpc-clnt.c:13:10:40:22 /usr/home/jenkins/root/workspace/freebsd-smoke/rpc/rpc-lib/src/rpc-clnt.c: In function 'rpc_clnt_handle_cbk':10:40:22 /usr/home/jenkins/root/workspace/freebsd-smoke/rpc/rpc-lib/src/rpc-clnt.c:686:12: warning: format '%lu' expects argument of type 'long unsigned int', but argument 2 has type 'u_int32_t {aka unsigned int}' [-Wformat=]10:40:22 "receivd rpc message (XID: 0x%" GF_PRI_RPC_XID

10:40:22 ^

May be it is because off_t is 32 bytes in freebsd? If so, then do you advise doing this in libglusterfs/src/glusterfs/sysca.h just above the declaration of sys_copy_file_range? (and may be in compat.h as well?)

#if !defined(GF_LINUX_HOST_OS) typedef loff_t off64_t #endif

Or

do you think loff_t has to be changed to off64_t across all the components of the gluster stack that are part of this change?

Regards, Raghavendra

to libglusterfs/src/syscall.h, immediatedly before the decl of

sys_copy_file_range().

Or....

While the man copy_file_range(2) man page says it's loff_t, the decl in <unistd.h> says it's __off64_t. And I don't have a recent POSIX spec to see what's in the actual spec.

But since the offset parameters are actually pointers I think it's not worth getting bogged down in this. I'd just change the loff_t to off64_t, which both *BSD and Linux have, and be done.

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/gluster/glusterfs/issues/536#issuecomment-445246211, or mute the thread https://github.com/notifications/unsubscribe-auth/AAmAbJUj39Z1ohwRhIBgx06yDU8EEso0ks5u2njsgaJpZM4YDL6- .

raghavendrabhat avatar Dec 07 '18 14:12 raghavendrabhat

copy_file_range(2) is not POSIX, it's a Linux/GNU extension. As such I'd say the decl in <unistd.h> is (more) authoritative than the man page. <sys/types.h> (i.e. <bits/types.h>) is where loff_t is typedef'd: ... typedef __off64_t __loff_t; ...

Both Linux and FreeBSD have ... typedef __off64_t off64_t; ...

I would just use off64_t in the decl and defn of sys_copy_file_range(), and I would use the off64_t type everywhere you have added calls sys_copy_file_range().

kalebskeithley avatar Dec 07 '18 16:12 kalebskeithley

The initial version of the patch is now merged.

amarts avatar Dec 17 '18 05:12 amarts

A patch https://review.gluster.org/21881 has been posted that references this issue.

cluster/afr: Refactor internal locking code to allow multiple inodelks

For implementing copy_file_range fop, AFR needs to perform two inodelks in the same transaction. This patch brings in the necessary structure to make it easier to do so.

Entry-locks in AFR were already taking multiple entry-locks on different inodes with the respective basenames. This patch extends the logic in inodelks to use the same lockee_t structure. This lead to removal of quite a lot of duplicate code present in afr-lk-common.c as both the locks are doing same things except 'winding' part.

updates: #536 Change-Id: Ibfce7e3f260bb27b18645152ec680c33866fe0ae Signed-off-by: Pranith Kumar K [email protected]

gluster-ant avatar Dec 18 '18 12:12 gluster-ant

A patch https://review.gluster.org/21997 has been posted that references this issue.

cluster/dht: copy_file_range fop added to DHT

  • This commit just adds support for the case where the cached subvolumes of both the source and the destination fd are same. Otherwise, ENOTSUP is returned back. In future, add changes where, DHT can read from the source and write to the destination.

Change-Id: I9a384574d3e355ad9f98fd67e7cb70acbe6b4a54 fixes: #536 Signed-off-by: Raghavendra Bhat [email protected]

gluster-ant avatar Jan 07 '19 23:01 gluster-ant

@pranithk

I am trying to implement the copy_file_range fop in AFR. I have a few doubts.

So, afr does this in afr_lock function for AFR_DATA_TRANSACTION and AFR_METADATA_TRANSACTION (IIUC copy_file_range is data transaction)

switch (local->transaction.type) { | case AFR_DATA_TRANSACTION: | case AFR_METADATA_TRANSACTION: | for (i = 0; i < int_lock->lockee_count; i++) { | afr_set_transaction_flock(this, local, &int_lock->lockee[i]); | }

And in afr_set_transaction_flock, we set the starting offset of the file on which the lock is being attempted and also the length of the lock range.

As of now, the function gets the start and length from local->transaction.start and local->transaction.len respectively. It is fine for fops like write, truncate etc where we are operating on only one inode. Whereas for copy_file_range, there are 2 fds with their respective offsets. So, we need track the starting offsets of the lock in local->transaction structure using 2 variables. I am planning to add another variable called start2 in local->transaction.

Do you foresee any issues with that? Can it cause any problems for healing or any other tasks? (Especially for checking the overlapping locks etc).

raghavendrabhat avatar Jan 10 '19 22:01 raghavendrabhat

@raghavendrabhat No issues with that. One thing you need to make sure of is, disabling eager-lock for this fop. You send your first draft of the patch. I can add in the details and resend the patch considering eager-lock etc.

pranithk avatar Jan 11 '19 03:01 pranithk

@raghavendrabhat Can I get a write-up of what is supported in release-6 for this feature? I know there is pending work, but want to see if parts of it can be announced for release-6.

ShyamsundarR avatar Feb 18 '19 15:02 ShyamsundarR

@ShyamsundarR For release-6, copy_file_range is supported on single brick volumes only. And even with that, there is a dependency on the kernel version used. For someone to be able to use copy_file_range while accessing via native fuse client, then IIUC kernel 4.20 or above is needed. Otherwise, the fuse kernel module itself does not contain the support for the fop.

The AFR and DHT support for copy_file_range is still a work in progress.

raghavendrabhat avatar Feb 18 '19 21:02 raghavendrabhat

@raghavendrabhat any progress on this? Should we be looking at reflink() based enhancements you were planning as part of release-8 activity?

amarts avatar Dec 03 '19 06:12 amarts