[Bugs] [Bug 1289068] New: libgfapi: Errno incorrectly set to EINVAL even on success
bugzilla at redhat.com
bugzilla at redhat.com
Mon Dec 7 11:33:48 UTC 2015
https://bugzilla.redhat.com/show_bug.cgi?id=1289068
Bug ID: 1289068
Summary: libgfapi: Errno incorrectly set to EINVAL even on
success
Product: GlusterFS
Version: 3.7.6
Component: libgfapi
Severity: urgent
Assignee: bugs at gluster.org
Reporter: ppai at redhat.com
QA Contact: sdharane at redhat.com
CC: bugs at gluster.org, gluster-bugs at redhat.com
Description of problem:
Errno is incorrectly set to EINVAL even on success, for subsequent glfs_*
calls.
[root at 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"
}
--
You are receiving this mail because:
You are on the CC list for the bug.
You are the assignee for the bug.
More information about the Bugs
mailing list