From 851ea76c04a8139ef307070550f8b4461a819bc6 Mon Sep 17 00:00:00 2001 From: Soumya Koduri Date: Wed, 25 May 2016 14:38:31 +0530 Subject: gfapi/handleops: Avoid using glfd during create To avoid leaking glfd while creating a file using handleops and since application shall not be interested in it, use the 'fd' object directly which can be un'refed post create. This is backport of below mainline patch - http://review.gluster.org/14532 > Change-Id: I119874ffb63fb4aa18f846ba1fdbe77874b66a54 > BUG: 1339553 > Signed-off-by: Soumya Koduri > Signed-off-by: Jiffin Tony Thottan > Reviewed-on: http://review.gluster.org/14532 > NetBSD-regression: NetBSD Build System > Reviewed-by: Niels de Vos > CentOS-regression: Gluster Build System > Tested-by: Gluster Build System > Smoke: Gluster Build System (cherry picked from commit 763ed1017b0011934ad2414d7396c46e528ea5b3) Change-Id: I119874ffb63fb4aa18f846ba1fdbe77874b66a54 BUG: 1351877 Signed-off-by: Soumya Koduri Reviewed-by: Kaleb S KEITHLEY Reviewed-on: http://review.gluster.org/14840 NetBSD-regression: NetBSD Build System CentOS-regression: Gluster Build System Reviewed-by: Niels de Vos Smoke: Gluster Build System --- api/src/glfs-handleops.c | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) (limited to 'api') diff --git a/api/src/glfs-handleops.c b/api/src/glfs-handleops.c index af58691bd8b..1c5546ec427 100644 --- a/api/src/glfs-handleops.c +++ b/api/src/glfs-handleops.c @@ -708,7 +708,7 @@ pub_glfs_h_creat (struct glfs *fs, struct glfs_object *parent, const char *path, int flags, mode_t mode, struct stat *stat) { int ret = -1; - struct glfs_fd *glfd = NULL; + fd_t *fd = NULL; xlator_t *subvol = NULL; inode_t *inode = NULL; loc_t loc = {0, }; @@ -737,6 +737,7 @@ pub_glfs_h_creat (struct glfs *fs, struct glfs_object *parent, const char *path, /* get/refresh the in arg objects inode in correlation to the xlator */ inode = glfs_resolve_inode (fs, subvol, parent); if (!inode) { + ret = -1; errno = ESTALE; goto out; } @@ -758,24 +759,17 @@ pub_glfs_h_creat (struct glfs *fs, struct glfs_object *parent, const char *path, GLFS_LOC_FILL_PINODE (inode, loc, ret, errno, out, path); - glfd = glfs_fd_new (fs); - if (!glfd) { - ret = -1; - errno = ENOMEM; - goto out; - } - - glfd->fd = fd_create (loc.inode, getpid()); - if (!glfd->fd) { + fd = fd_create (loc.inode, getpid()); + if (!fd) { ret = -1; errno = ENOMEM; goto out; } - glfd->fd->flags = flags; + fd->flags = flags; /* fop/op */ - ret = syncop_create (subvol, &loc, flags, mode, glfd->fd, - &iatt, xattr_req, NULL); + ret = syncop_create (subvol, &loc, flags, mode, fd, &iatt, + xattr_req, NULL); DECODE_SYNCOP_ERR (ret); /* populate out args */ @@ -791,10 +785,6 @@ pub_glfs_h_creat (struct glfs *fs, struct glfs_object *parent, const char *path, ret = glfs_create_object (&loc, &object); } - glfd->fd->flags = flags; - fd_bind (glfd->fd); - glfs_fd_bind (glfd); - out: if (ret && object != NULL) { /* Release the held reference */ @@ -810,12 +800,8 @@ out: if (xattr_req) dict_unref (xattr_req); - if (ret && glfd) { - GF_REF_PUT (glfd); - glfd = NULL; - } else if (glfd) { - glfd->state = GLFD_OPEN; - } + if (fd) + fd_unref(fd); glfs_subvol_done (fs, subvol); -- cgit