From 7646169f20d2e2f23c6033347f019ee60521a524 Mon Sep 17 00:00:00 2001 From: Anand Avati Date: Thu, 2 May 2013 20:01:18 -0700 Subject: gfapi: add new API glfs_dup() to copy a file descriptor Duplicate a glfs_fd file descriptor. Inherit the internal fd_t with a reference. Change-Id: Ib30e9a46b608b9f78202957f4dab6ba6265a9ec0 BUG: 953694 Signed-off-by: Anand Avati Reviewed-on: http://review.gluster.org/5109 Reviewed-by: Raghavendra Talur Tested-by: Gluster Build System --- api/src/glfs-fops.c | 42 ++++++++++++++++++++++++++++++++++++++++++ api/src/glfs.h | 1 + 2 files changed, 43 insertions(+) (limited to 'api') diff --git a/api/src/glfs-fops.c b/api/src/glfs-fops.c index 231db481..66e7d69f 100644 --- a/api/src/glfs-fops.c +++ b/api/src/glfs-fops.c @@ -2882,3 +2882,45 @@ out: return ret; } + + +struct glfs_fd * +glfs_dup (struct glfs_fd *glfd) +{ + xlator_t *subvol = NULL; + fd_t *fd = NULL; + glfs_fd_t *dupfd = NULL; + struct glfs *fs = NULL; + + __glfs_entry_fd (glfd); + + fs = glfd->fs; + subvol = glfs_active_subvol (fs); + if (!subvol) { + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd (fs, subvol, glfd); + if (!fd) { + errno = EBADFD; + goto out; + } + + dupfd = glfs_fd_new (fs); + if (!dupfd) { + errno = ENOMEM; + goto out; + } + + dupfd->fd = fd_ref (fd); +out: + if (fd) + fd_unref (fd); + if (dupfd) + glfs_fd_bind (dupfd); + + glfs_subvol_done (fs, subvol); + + return dupfd; +} diff --git a/api/src/glfs.h b/api/src/glfs.h index aeabfdf0..f472ca4e 100644 --- a/api/src/glfs.h +++ b/api/src/glfs.h @@ -461,6 +461,7 @@ char *glfs_realpath (glfs_t *fs, const char *path, char *resolved_path); */ int glfs_posix_lock (glfs_fd_t *fd, int cmd, struct flock *flock); +glfs_fd_t *glfs_dup (glfs_fd_t *fd); __END_DECLS -- cgit