Bug 1296007 - libgfapi: Errno incorrectly set to EINVAL even on success
Summary: libgfapi: Errno incorrectly set to EINVAL even on success
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: GlusterFS
Classification: Community
Component: libgfapi
Version: 3.7.7
Hardware: All
OS: All
high
low
Target Milestone: ---
Assignee: Prashanth Pai
QA Contact: Sudhir D
URL:
Whiteboard:
Depends On: 1289068
Blocks: glusterfs-3.7.9
TreeView+ depends on / blocked
 
Reported: 2016-01-06 05:58 UTC by Prashanth Pai
Modified: 2016-04-19 07:23 UTC (History)
4 users (show)

Fixed In Version: glusterfs-3.7.9
Doc Type: Bug Fix
Doc Text:
Clone Of: 1289068
Environment:
Last Closed: 2016-03-28 04:19:11 UTC
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Embargoed:


Attachments (Terms of Use)

Description Prashanth Pai 2016-01-06 05:58:13 UTC
+++ This bug was initially created as a clone of Bug #1289068 +++

Description of problem:
Errno is incorrectly set to EINVAL even on success, for subsequent glfs_* calls.

[root@hummingbird ~]# rpm -qa | grep glusterfs
glusterfs-3.7.6-1.fc22.x86_64
glusterfs-cli-3.7.6-1.fc22.x86_64
glusterfs-devel-3.7.6-1.fc22.x86_64
glusterfs-libs-3.7.6-1.fc22.x86_64
glusterfs-client-xlators-3.7.6-1.fc22.x86_64
glusterfs-fuse-3.7.6-1.fc22.x86_64
glusterfs-server-3.7.6-1.fc22.x86_64
glusterfs-extra-xlators-3.7.6-1.fc22.x86_64
glusterfs-api-devel-3.7.6-1.fc22.x86_64
glusterfs-api-3.7.6-1.fc22.x86_64

Example:
Even though glfs_fstat() returns success (zero), errno is set to EINVAL. It doesn't matter that the second glfs_* call is glfs_stat(). Even if you have glfs_write() twice, errno is set to EINVAL for the second call.


#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>

#include "api/glfs.h"

int main () {

        glfs_t *fs = NULL;
        int ret = 0;
        glfs_fd_t *glfd = NULL;
        char *buf = NULL;
        struct stat sb;

        fs = glfs_new ("test");
        glfs_set_volfile_server (fs, "tcp", "localhost", 24007);
        glfs_set_logging (fs, NULL, 7);
        glfs_init (fs);
        glfd = glfs_creat(fs, "/file.txt", O_WRONLY, 0666);

        // Comment out this write to see the bug magically go away!
        ret = glfs_write (glfd, "qwertyuiopasdfghjklzxcvbnm", 26, 0);
        printf("errno after write(), before fstat(): %d\n", errno);
        ret = glfs_fstat(glfd, &sb);
        printf("glfs_fstat() returned: %d\n", ret);
        printf("errno after: %d\n", errno);

        ret = glfs_close(glfd);
        ret = glfs_fini (fs);
}  


Steps to Reproduce:
*******************

# gcc err.c -I /usr/include/glusterfs/ -lgfapi -O0 -ggdb -o ./err
# ./err

Actual results:
***************

# ./err
errno after write(), before fstat(): 0
glfs_fstat() returned: 0
errno after: 22

// After commenting out first call - glfs_write()

# ./err
errno after write(), before fstat(): 0
glfs_fstat() returned: 0
errno after: 0

Expected results:
*****************

# ./err
errno after write(), before fstat(): 0
glfs_fstat() returned: 0
errno after: 0


Additional info: 
****************
C programs usually check return value first and then the errno. But the control flow in golang is different.

ret, err := C.glfs_fstat(fd.fd, (*C.struct_stat)(unsafe.Pointer(stat)))
if err != nil {
    // Failure! handle error
} else {
    // Success! consume entity returned by C call. In this case "stat"
}

--- Additional comment from Prashanth Pai on 2015-12-07 06:41:52 EST ---

This should also reproduce the behavior:

        ret = glfs_write (glfd, "qwertyuiopasdfghjklzxcvbnm", 26, 0);
        printf("errno after first write(): %d\n", errno);
        ret = glfs_write (glfd, "qwertyuiopasdfghjklzxcvbnm", 26, 0);
        printf("errno after second write(): %d\n", errno);

# ./err
errno after first write(): 0
errno after second write(): 22

--- Additional comment from Vijay Bellur on 2015-12-08 06:15:57 EST ---

REVIEW: http://review.gluster.org/12909 (Fix errno being set to EINVAL even on success) posted (#1) for review on master by Prashanth Pai (ppai)

--- Additional comment from Vijay Bellur on 2015-12-08 10:37:13 EST ---

REVIEW: http://review.gluster.org/12909 (Fix errno being set to EINVAL even on success) posted (#2) for review on master by Vijay Bellur (vbellur)

--- Additional comment from Vijay Bellur on 2015-12-08 16:49:27 EST ---

REVIEW: http://review.gluster.org/12909 (api: Fix errno being set to EINVAL even on success) posted (#3) for review on master by Vijay Bellur (vbellur)

--- Additional comment from Vijay Bellur on 2015-12-08 16:49:33 EST ---

REVIEW: http://review.gluster.org/12909 (api: Fix errno being set to EINVAL even on success) posted (#4) for review on master by Vijay Bellur (vbellur)

--- Additional comment from Vijay Bellur on 2016-01-05 10:41:14 EST ---

COMMIT: http://review.gluster.org/12909 committed in master by Shyamsundar Ranganathan (srangana) 
------
commit 1e779acec75842b0e8d5a34ac2ea52f9caeff4d1
Author: Prashanth Pai <ppai>
Date:   Tue Dec 8 16:28:39 2015 +0530

    api: Fix errno being set to EINVAL even on success
    
    BUG: 1289068
    Change-Id: I7905ac70a537f23e1844c097a24eaa6cb762fb82
    Signed-off-by: Prashanth Pai <ppai>
    Reviewed-on: http://review.gluster.org/12909
    Tested-by: NetBSD Build System <jenkins.org>
    Tested-by: Gluster Build System <jenkins.com>
    Reviewed-by: jiffin tony Thottan <jthottan>
    Reviewed-by: Kaushal M <kaushal>
    Reviewed-by: Shyamsundar Ranganathan <srangana>

Comment 1 Vijay Bellur 2016-01-06 06:06:47 UTC
REVIEW: http://review.gluster.org/13179 (api: Fix errno being set to EINVAL even on success) posted (#2) for review on release-3.7 by Prashanth Pai (ppai)

Comment 2 Vijay Bellur 2016-01-20 13:59:02 UTC
REVIEW: http://review.gluster.org/13179 (api: Fix errno being set to EINVAL even on success) posted (#3) for review on release-3.7 by Prashanth Pai (ppai)

Comment 3 Vijay Bellur 2016-02-23 12:48:55 UTC
COMMIT: http://review.gluster.org/13179 committed in release-3.7 by Niels de Vos (ndevos) 
------
commit 9950884e280e393c2c1bdab189ea3aa1716599e8
Author: Prashanth Pai <ppai>
Date:   Tue Dec 8 16:28:39 2015 +0530

    api: Fix errno being set to EINVAL even on success
    
    BUG: 1296007
    Change-Id: I7905ac70a537f23e1844c097a24eaa6cb762fb82
    Signed-off-by: Prashanth Pai <ppai>
    Reviewed-on: http://review.gluster.org/12909
    Tested-by: NetBSD Build System <jenkins.org>
    Tested-by: Gluster Build System <jenkins.com>
    Reviewed-by: jiffin tony Thottan <jthottan>
    Reviewed-by: Kaushal M <kaushal>
    Reviewed-by: Shyamsundar Ranganathan <srangana>
    Reviewed-on: http://review.gluster.org/13179
    Smoke: Gluster Build System <jenkins.com>
    NetBSD-regression: NetBSD Build System <jenkins.org>
    CentOS-regression: Gluster Build System <jenkins.com>
    Reviewed-by: Niels de Vos <ndevos>

Comment 4 Kaushal 2016-04-19 07:23:31 UTC
This bug is getting closed because a release has been made available that should address the reported issue. In case the problem is still not fixed with glusterfs-3.7.9, please open a new bug report.

glusterfs-3.7.9 has been announced on the Gluster mailinglists [1], packages for several distributions should become available in the near future. Keep an eye on the Gluster Users mailinglist [2] and the update infrastructure for your distribution.

[1] https://www.gluster.org/pipermail/gluster-users/2016-March/025922.html
[2] http://thread.gmane.org/gmane.comp.file-systems.gluster.user


Note You need to log in before you can comment on or make changes to this bug.