From ba1a401e142ad8884f9d3f13c51f7d5b17d008fc 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.7. 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: 1315557 Change-Id: I142dde11923244809b03fcca8cd4c2f7d5ff3929 Signed-off-by: Niels de Vos Reviewed-on: http://review.gluster.org/13631 Smoke: Gluster Build System Reviewed-by: Shyamsundar Ranganathan NetBSD-regression: NetBSD Build System CentOS-regression: Gluster Build System Reviewed-by: Vijay Bellur --- api/src/glfs-fops.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'api') diff --git a/api/src/glfs-fops.c b/api/src/glfs-fops.c index ff55bf3d673..ce0cebc20c1 100644 --- a/api/src/glfs-fops.c +++ b/api/src/glfs-fops.c @@ -525,6 +525,7 @@ pub_glfs_lseek (struct glfs_fd *glfd, off_t offset, int whence) { struct stat sb = {0, }; int ret = -1; + off_t off = -1; DECLARE_OLD_THIS; __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); @@ -532,9 +533,11 @@ pub_glfs_lseek (struct glfs_fd *glfd, off_t offset, int whence) 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); @@ -544,11 +547,16 @@ pub_glfs_lseek (struct glfs_fd *glfd, off_t offset, int whence) } glfd->offset = sb.st_size + offset; break; + default: + errno = EINVAL; } __GLFS_EXIT_FS; - return glfd->offset; + if (ret != -1) + off = glfd->offset; + + return off; invalid_fs: return -1; -- cgit