From caccd6c205cd324ef184ac6333fb05acd0cc5d4e Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Tue, 8 Mar 2016 05:39:01 +0100 Subject: gfapi: return EINVAL for unsupported lseek() operations GlusterFS 3.8 contains support for SEEK_DATA/SEEK_HOLE. This protocol extension is not available in 3.6. libgfapi needs to handle unsupported SEEK_* operations correctly, by returning -1 and setting errno to EINVAL. This change is different from the patch in the master branch, it is only needed to do the improved error checking in this version. BUG: 1315558 Change-Id: I142dde11923244809b03fcca8cd4c2f7d5ff3929 Signed-off-by: Niels de Vos Reviewed-on: http://review.gluster.org/13633 Smoke: Gluster Build System NetBSD-regression: NetBSD Build System CentOS-regression: Gluster Build System Reviewed-by: Shyamsundar Ranganathan Reviewed-by: Raghavendra Bhat --- api/src/glfs-fops.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/api/src/glfs-fops.c b/api/src/glfs-fops.c index 722cd5e2736..5c15df0490b 100644 --- a/api/src/glfs-fops.c +++ b/api/src/glfs-fops.c @@ -446,15 +446,18 @@ pub_glfs_lseek (struct glfs_fd *glfd, off_t offset, int whence) { struct stat sb = {0, }; int ret = -1; + off_t off = -1; __glfs_entry_fd (glfd); switch (whence) { case SEEK_SET: glfd->offset = offset; + ret = 0; break; case SEEK_CUR: glfd->offset += offset; + ret = 0; break; case SEEK_END: ret = pub_glfs_fstat (glfd, &sb); @@ -464,9 +467,14 @@ pub_glfs_lseek (struct glfs_fd *glfd, off_t offset, int whence) } glfd->offset = sb.st_size + offset; break; + default: + errno = EINVAL; } - return glfd->offset; + if (ret != -1) + off = glfd->offset; + + return off; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_lseek, 3.4.0); -- cgit