int
main (int argc, char *argv[])
{
    glfs_t    *fs = NULL;
    glfs_fd_t *fd = NULL;
    int        ret = 1;

    if (argc != 4) {
        fprintf (stderr, "Syntax: %s <host> <volname> <file-path> \n", argv[0]);
        return 1;
    }

    fs = glfs_new (argv[2]);
    if (!fs) {
        fprintf (stderr, "glfs_new: returned NULL\n");
        return 1;
    }

    ret = glfs_set_volfile_server (fs, "tcp", argv[1], 24007);
    if (ret != 0) {
        fprintf (stderr, "glfs_set_volfile_server: retuned %d\n", ret);
        goto out;
    }
    ret = glfs_set_logging (fs, "/var/log/glusterfs/glfs-dis.log", 7);
    if (ret != 0) {
        fprintf (stderr, "glfs_set_logging: returned %d\n", ret);
        goto out;
    }
    ret = glfs_init (fs);
    if (ret != 0) {
        fprintf (stderr, "glfs_init: returned %d\n", ret);
        goto out;
    }

    fd = glfs_open (fs, argv[3], O_RDWR);
    if (fd == NULL) {
        fprintf (stderr, "glfs_open: returned NULL\n");
        goto out;
    }

    /* Zero-fill "foo" with 10MB of data */
    ret = glfs_zerofill (fd, 0, 10485760);
    if (ret <= 0) {
        fprintf (stderr, "glfs_zerofill: returned %d\n", ret);
        goto out;
    }

    glfs_close(fd);

    ret = 0;

out:
    glfs_fini (fs);
    return ret;
}
Example #2
0
static struct glfs *qemu_gluster_init(GlusterConf *gconf, const char *filename,
                                      Error **errp)
{
    struct glfs *glfs = NULL;
    int ret;
    int old_errno;

    ret = qemu_gluster_parseuri(gconf, filename);
    if (ret < 0) {
        error_setg(errp, "Usage: file=gluster[+transport]://[server[:port]]/"
                   "volname/image[?socket=...]");
        errno = -ret;
        goto out;
    }

    glfs = glfs_new(gconf->volname);
    if (!glfs) {
        goto out;
    }

    ret = glfs_set_volfile_server(glfs, gconf->transport, gconf->server,
            gconf->port);
    if (ret < 0) {
        goto out;
    }

    /*
     * TODO: Use GF_LOG_ERROR instead of hard code value of 4 here when
     * GlusterFS makes GF_LOG_* macros available to libgfapi users.
     */
    ret = glfs_set_logging(glfs, "-", 4);
    if (ret < 0) {
        goto out;
    }

    ret = glfs_init(glfs);
    if (ret) {
        error_setg_errno(errp, errno,
                         "Gluster connection failed for server=%s port=%d "
                         "volume=%s image=%s transport=%s", gconf->server,
                         gconf->port, gconf->volname, gconf->image,
                         gconf->transport);
        goto out;
    }
    return glfs;

out:
    if (glfs) {
        old_errno = errno;
        glfs_fini(glfs);
        errno = old_errno;
    }
    return NULL;
}
Example #3
0
int
main(int argc, char *argv[])
{
    int ret = 0;
    char *hostname = NULL;
    char *volname = NULL;
    char *logfile = NULL;
    glfs_t *fs = NULL;

    if (argc != 4) {
        fprintf(stderr, "Invalid argument\n");
        exit(1);
    }

    hostname = argv[1];
    volname = argv[2];
    logfile = argv[3];

    fs = glfs_new(volname);
    if (!fs) {
        LOG_ERR("glfs_new failed");
        return -1;
    }

    ret = glfs_set_volfile_server(fs, "tcp", hostname, 24007);
    if (ret < 0) {
        LOG_ERR("glfs_set_volfile_server failed");
        goto err;
    }

    ret = glfs_set_logging(fs, logfile, 7);
    if (ret < 0) {
        LOG_ERR("glfs_set_logging failed");
        goto err;
    }

    ret = glfs_init(fs);
    if (ret < 0) {
        LOG_ERR("glfs_init failed");
        goto err;
    }

    glfs_fini(fs);
    fs = NULL;
    return 0;
err:
    glfs_fini(fs);
    fs = NULL;

    return -1;
}
Example #4
0
int
main (int argc, char *argv[])
{
	glfs_t    *fs = NULL;
	int        ret = 0;
	glfs_fd_t *fd = NULL;
	struct stat sb = {0, };
	char       readbuf[32];
	char       writebuf[32];

	char      *volname = "iops";
	char      *filename = "/filename2";

	fs = glfs_new (volname);
	if (!fs) {
		fprintf (stderr, "glfs_new: returned NULL\n");
		return 1;
	}

//	ret = glfs_set_volfile (fs, "/tmp/filename.vol");

	ret = glfs_set_volfile_server (fs, "socket", "localhost", 24007);

//	ret = glfs_set_volfile_server (fs, "unix", "/tmp/gluster.sock", 0);

	ret = glfs_set_logging (fs, "/dev/stderr", 7);

	ret = glfs_init (fs);

	fprintf (stderr, "glfs_init: returned %d\n", ret);


	ret = glfs_lstat (fs, filename, &sb);
	fprintf (stderr, "%s: (%d) %s\n", filename, ret, strerror (errno));

	fd = glfs_creat (fs, filename, O_RDWR, 0644);
	fprintf (stderr, "%s: (%p) %s\n", filename, fd, strerror (errno));

	sprintf (writebuf, "hi there\n");
	ret = glfs_write (fd, writebuf, 32, 0);

	glfs_lseek (fd, 0, SEEK_SET);

	ret = glfs_read (fd, readbuf, 32, 0);

	printf ("read %d, %s", ret, readbuf);

	glfs_close (fd);

	return ret;
}
Example #5
0
int
main(int argc, char *argv[])
{
    glfs_t *fs = NULL;
    int ret = 0, i;
    glfs_fd_t *fd = NULL;
    char readbuf[32];
    char *logname = NULL;
    char *hostname = NULL;
    char *volname = NULL;

    fprintf(stderr, "Starting libgfapi_fini\n");

    if (argc < 4) {
        fprintf(stderr, "Invalid argument\n");
        exit(1);
    }

    hostname = argv[1];
    volname = argv[2];
    logname = argv[3];

    fs = glfs_new(volname);
    if (!fs) {
        fprintf(stderr, "glfs_new: returned NULL\n");
        exit(1);
    }

    ret = glfs_set_volfile_server(fs, "tcp", hostname, 0);
    LOG_ERR("glfs_set_volfile_server", ret);

    ret = glfs_set_logging(fs, logname, 7);
    LOG_ERR("glfs_set_logging", ret);

    /* Do not call glfs_init.
     * glfs_fini() shouldn't hang in that case*/
    ret = glfs_fini(fs);
    LOG_ERR("glfs_fini", ret);
    fprintf(stderr, "End of libgfapi_fini\n");

    exit(0);
}
Example #6
0
glfs_t *
setup_new_client(char *hostname, char *volname, char *log_file, int flag)
{
        int ret = 0;
        glfs_t *fs = NULL;

        fs = glfs_new (volname);
        if (!fs) {
                fprintf (stderr, "\nglfs_new: returned NULL (%s)\n",
                                 strerror (errno));
                goto error;
        }

        ret = glfs_set_volfile_server (fs, "tcp", hostname, 24007);
        if (ret < 0) {
                fprintf (stderr, "\nglfs_set_volfile_server failed ret:%d (%s)\n",
                                 ret, strerror (errno));
                goto error;
        }

        ret = glfs_set_logging (fs, log_file, 7);
        if (ret < 0) {
                fprintf (stderr, "\nglfs_set_logging failed with ret: %d (%s)\n",
                                 ret, strerror (errno));
                goto error;
        }

        if (flag == NO_INIT)
                goto out;

        ret = glfs_init (fs);
        if (ret < 0) {
                fprintf (stderr, "\nglfs_init failed with ret: %d (%s)\n",
                                  ret, strerror (errno));
                goto error;
        }

out:
        return fs;
error:
        return NULL;
}
Example #7
0
static int
cat_without_context ()
{
        glfs_t *fs = NULL;
        int ret = -1;

        ret = gluster_getfs (&fs, state->gluster_url);
        if (ret == -1) {
                error (0, errno, state->url);
                goto out;
        }

        ret = apply_xlator_options (fs, &state->xlator_options);
        if (ret == -1) {
                error (0, errno, "failed to apply translator options");
                goto out;
        }

        if (state->debug) {
                ret = glfs_set_logging (fs, "/dev/stderr", GF_LOG_DEBUG);

                if (ret == -1) {
                        error (0, errno, "failed to set logging level");
                        goto out;
                }
        }

        ret = gluster_get (fs, state->gluster_url->path);
        if (ret == -1) {
                goto out;
        }

        ret = 0;

out:
        if (fs) {
                glfs_fini (fs);
        }

        return ret;
}
Example #8
0
glfs_t *
init_glfs (const char *hostname, const char *volname,
           const char *logfile)
{
        int     ret     = -1;
        glfs_t *fs      = NULL;

        fs = glfs_new (volname);
        if (!fs) {
                LOG_ERR ("glfs_new failed");
                return NULL;
        }

        ret = glfs_set_volfile_server (fs, "tcp", hostname, 24007);
        if (ret < 0) {
                LOG_ERR ("glfs_set_volfile_server failed");
                goto out;
        }

        ret = glfs_set_logging (fs, logfile, 7);
        if (ret < 0) {
                LOG_ERR ("glfs_set_logging failed");
                goto out;
        }

        ret = glfs_init (fs);
        if (ret < 0) {
                LOG_ERR ("glfs_init failed");
                goto out;
        }

        ret = 0;
out:
        if (ret) {
                glfs_fini (fs);
                fs = NULL;
        }

        return fs;
}
Example #9
0
int
main(int argc, char *argv[])
{
    int ret = -1;
    int flags = O_RDWR | O_SYNC;
    glfs_t *fs = NULL;
    glfs_fd_t *fd = NULL;
    char *volname = NULL;
    char *logfile = NULL;
    const char *filename = "file_tmp";
    struct glfs_object *object = NULL;
    acl_t acl = NULL;
    struct stat sb;

    if (argc != 3) {
        fprintf(stderr, "Invalid argument\n");
        return 1;
    }

    volname = argv[1];
    logfile = argv[2];

    fs = glfs_new(volname);
    if (!fs)
        VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_new", ret, out);

    ret = glfs_set_volfile_server(fs, "tcp", "localhost", 24007);
    VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_set_volfile_server", ret, out);

    ret = glfs_set_logging(fs, logfile, 7);
    VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_set_logging", ret, out);

    ret = glfs_init(fs);
    VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_init", ret, out);

    fd = glfs_creat(fs, filename, flags, 0044);
    if (fd == NULL) {
        ret = -1;
        VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_creat", ret, out);
    }
    glfs_close(fd);

    object = glfs_h_lookupat(fs, NULL, filename, NULL, 0);
    if (object == NULL) {
        ret = -1;
        VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_h_lookupat", ret, out);
    }

    ret = glfs_chown(fs, filename, 99, 99);
    VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_chown", ret, out);

    ret = glfs_setfsuid(99);
    VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_setfsuid", ret, out);

    ret = glfs_setfsgid(99);
    VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_setfsgid", ret, out);

    acl = glfs_h_acl_get(fs, object, ACL_TYPE_ACCESS);
    if (acl == NULL) {
        ret = -1;
        VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_h_acl_get", ret, out);
    }

    ret = glfs_h_acl_set(fs, object, ACL_TYPE_ACCESS, acl);
    VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_h_acl_get", ret, out);
out:
    glfs_setfsuid(0);
    glfs_setfsgid(0);

    if (object)
        glfs_h_close(object);

    if (fs)
        glfs_fini(fs);

    return ret;
}
Example #10
0
int
main(int argc, char *argv[])
{
    int ret = 1;
    int opcode = -1;
    off_t offset = 0;
    size_t len = 0;
    glfs_t *fs = NULL;
    glfs_fd_t *fd = NULL;

    if (argc != 8) {
        fprintf(stderr,
                "Syntax: %s <host> <volname> <opcode> <offset> <len> "
                "<file-path> <log-file>\n",
                argv[0]);
        return 1;
    }

    fs = glfs_new(argv[2]);
    if (!fs) {
        fprintf(stderr, "glfs_new: returned NULL\n");
        return 1;
    }

    ret = glfs_set_volfile_server(fs, "tcp", argv[1], 24007);
    if (ret != 0) {
        fprintf(stderr, "glfs_set_volfile_server: returned %d\n", ret);
        goto out;
    }

    ret = glfs_set_logging(fs, argv[7], 7);
    if (ret != 0) {
        fprintf(stderr, "glfs_set_logging: returned %d\n", ret);
        goto out;
    }

    ret = glfs_init(fs);
    if (ret != 0) {
        fprintf(stderr, "glfs_init: returned %d\n", ret);
        goto out;
    }

    opcode = atoi(argv[3]);
    opcode = get_fallocate_flag(opcode);
    if (opcode < 0) {
        fprintf(stderr, "get_fallocate_flag: invalid flag \n");
        goto out;
    }

    offset = atoi(argv[4]);
    len = atoi(argv[5]);

    fd = glfs_open(fs, argv[6], O_RDWR);
    if (fd == NULL) {
        fprintf(stderr, "glfs_open: returned NULL\n");
        goto out;
    }

    ret = glfs_fallocate(fd, opcode, offset, len);
    if (ret <= 0) {
        fprintf(stderr, "glfs_fallocate: returned %d\n", ret);
        goto out;
    }

    ret = 0;

out:
    if (fd)
        glfs_close(fd);
    glfs_fini(fs);
    return ret;
}
Example #11
0
int
main(int argc, char *argv[])
{
    glfs_t *fs = NULL;
    int ret = 0, i, status = 0;
    glfs_fd_t *fd1 = NULL;
    glfs_fd_t *fd2 = NULL;
    glfs_fd_t *fd3 = NULL;
    char *filename = "file_tmp";
    char *volname = NULL;
    char *logfile = NULL;
    char *hostname = NULL;

    if (argc != 4) {
        fprintf(stderr, "Invalid argument\n");
        exit(1);
    }

    hostname = argv[1];
    volname = argv[2];
    logfile = argv[3];

    fs = glfs_new(volname);
    if (!fs) {
        fprintf(stderr, "glfs_new: returned NULL\n");
        return -1;
    }

    ret = glfs_set_volfile_server(fs, "tcp", hostname, 24007);
    LOG_ERR("glfs_set_volfile_server", ret);

    ret = glfs_set_logging(fs, logfile, 7);
    LOG_ERR("glfs_set_logging", ret);

    ret = glfs_init(fs);
    LOG_ERR("glfs_init", ret);

    fd1 = glfs_creat(fs, filename, O_RDWR | O_SYNC, 0644);
    if (fd1 <= 0) {
        ret = -1;
        LOG_ERR("glfs_creat", ret);
    }
    fprintf(stderr, "glfs-create fd1 - %d\n", fd1);

    fd2 = glfs_dup(fd1);
    fprintf(stderr, "glfs-dup fd2 - %d\n", fd2);

    fd3 = glfs_open(fs, filename, O_RDWR | O_SYNC);
    if (fd2 <= 0) {
        ret = -1;
        LOG_ERR("glfs_open", ret);
    }
    fprintf(stderr, "glfs-open fd3 - %d\n", fd3);

    /* TEST 1: Conflicting ranges, same lk_owner
     * lock1 (0, 10, lownera)
     * lock2 (5, 10, lownera)
     * Expected: should not fail but get merged
     */
    ret = lock_test(fd1, fd2, false, 0, 10, lownera, 8, 5, 10, lownera, 8);
    LOG_ERR("==== glfs_lock_test_1", ret);

    /* TEST 2: Conflicting ranges, different lk_owner
     * lock1 (0, 10, lownera) - already taken
     * lock2 (5, 10, lownerb)
     * Expected: should fail and not get merged
     */
    ret = lock_test(NULL, fd2, true, 0, 10, lownera, 8, 5, 10, lownerb, 8);
    LOG_ERR("==== glfs_lock_test_2", ret);

    /* TEST 3: Different ranges, same lk_owner
     * lock1 (0, 10, lownera) - already taken
     * lock2 (30, 10, lownera)
     * Expected: should not fail
     */
    ret = lock_test(NULL, fd2, false, 0, 10, lownera, 8, 30, 10, lownera, 8);
    LOG_ERR("==== glfs_lock_test_3", ret);

    /* TEST 4: Conflicting ranges, different lk_owner
     * lock1 (0, 10, lownera) - already taken
     * lock2 (50, 10, lownerb)
     * Expected: should not fail
     */
    ret = lock_test(NULL, fd2, false, 0, 10, lownera, 8, 50, 10, lownerb, 8);
    LOG_ERR("==== glfs_lock_test_4", ret);

    /* TEST 5: Close fd1 & retry TEST2
     * lock1 (not applicable)
     * lock2 (5, 10, lownerb)
     * Expected: should succeed now
     */
    ret = glfs_close(fd1);
    LOG_ERR("glfs_close", ret);

    ret = lock_test(NULL, fd2, false, 0, 10, lownera, 8, 5, 10, lownerb, 8);
    LOG_ERR("==== glfs_lock_test_5", ret);

    /* TEST 6: Check closing fd1 doesn't flush fd2 locks
     * retry TEST 4 but with fd2 and fd3.
     * lock1 (50, 10, lownerb) - already taken
     * lock2 (55, 10, lownerc)
     * Expected: should fail
     */
    ret = lock_test(NULL, fd3, true, 50, 10, lownerb, 8, 55, 10, lownerc, 8);
    LOG_ERR("==== glfs_lock_test_6", ret);

err:
    ret = glfs_close(fd2);
    LOG_ERR("glfs_close", ret);

    ret = glfs_close(fd3);
    LOG_ERR("glfs_close", ret);

out:
    if (fs) {
        ret = glfs_fini(fs);
        fprintf(stderr, "glfs_fini(fs) returned %d\n", ret);
    }

    if (ret)
        exit(1);
    exit(0);
}
Example #12
0
int
main(int argc, char *argv[])
{
    glfs_t *fs = NULL;
    glfs_t *fs2 = NULL;
    int ret = 0, i;
    glfs_fd_t *fd = NULL;
    char *filename = "/a1";
    char *filename2 = "/a2";
    struct stat sb = {
        0,
    };
    char *logfile = NULL;
    char *volname = NULL;
    char *hostname = NULL;
    int cnt = 1;
    int upcall_received = 0;
    struct glfs_upcall *cbk = NULL;
    struct glfs_object *root = NULL, *leaf = NULL;
    unsigned char globjhdl[GFAPI_HANDLE_LENGTH];
    unsigned char globjhdl2[GFAPI_HANDLE_LENGTH];

    fprintf(stderr, "Starting libgfapi_fini\n");
    if (argc != 4) {
        fprintf(stderr, "Invalid argument\n");
        exit(1);
    }

    hostname = argv[1];
    volname = argv[2];
    logfile = argv[3];

    fs = glfs_new(volname);
    if (!fs) {
        fprintf(stderr, "glfs_new: returned NULL\n");
        return 1;
    }

    ret = glfs_set_volfile_server(fs, "tcp", hostname, 24007);
    LOG_ERR("glfs_set_volfile_server", ret);

    ret = glfs_set_logging(fs, logfile, 7);
    LOG_ERR("glfs_set_logging", ret);

    ret = glfs_init(fs);
    LOG_ERR("glfs_init", ret);

    /* This does not block, but enables caching of events. Real
     * applications like NFS-Ganesha run this in a thread before activity
     * on the fs (through this instance) happens. */
    ret = glfs_h_poll_upcall(fs, &cbk);
    LOG_ERR("glfs_h_poll_upcall", ret);

    fs2 = glfs_new(volname);
    if (!fs) {
        fprintf(stderr, "glfs_new: returned NULL\n");
        return 1;
    }

    ret = glfs_set_volfile_server(fs2, "tcp", hostname, 24007);
    LOG_ERR("glfs_set_volfile_server", ret);

    ret = glfs_set_logging(fs2, logfile, 7);
    LOG_ERR("glfs_set_logging", ret);

    ret = glfs_init(fs2);
    LOG_ERR("glfs_init", ret);

    sleep(2);
    root = glfs_h_lookupat(fs, NULL, "/", &sb, 0);
    if (!root) {
        ret = -1;
        LOG_ERR("glfs_h_lookupat root", ret);
    }
    leaf = glfs_h_lookupat(fs, root, filename, &sb, 0);
    if (!leaf) {
        ret = -1;
        LOG_IF_NO_ERR("glfs_h_lookupat leaf", ret);
    }

    root = glfs_h_lookupat(fs2, NULL, "/", &sb, 0);
    if (!root) {
        ret = -1;
        LOG_ERR("glfs_h_lookupat root", ret);
    }
    leaf = glfs_h_creat(fs2, root, filename, O_RDWR, 0644, &sb);
    if (!leaf) {
        ret = -1;
        LOG_ERR("glfs_h_lookupat leaf", ret);
    }
    fprintf(stderr, "glfs_h_create leaf - %p\n", leaf);

    while (cnt++ < 5 && !upcall_received) {
        enum glfs_upcall_reason reason = 0;
        struct glfs_upcall_inode *in_arg = NULL;

        ret = glfs_h_poll_upcall(fs, &cbk);
        LOG_ERR("glfs_h_poll_upcall", ret);
        if (ret)
            goto retry;

        reason = glfs_upcall_get_reason(cbk);
        fprintf(stderr, "Upcall received(%d)\n", reason);

        if (reason == GLFS_UPCALL_INODE_INVALIDATE) {
            struct glfs_object *object = NULL;

            in_arg = glfs_upcall_get_event(cbk);
            object = glfs_upcall_inode_get_object(in_arg);

            ret = glfs_h_extract_handle(root, globjhdl + GLAPI_UUID_LENGTH,
                                        GFAPI_HANDLE_LENGTH);
            LOG_ERR("glfs_h_extract_handle", (ret != 16));

            ret = glfs_h_extract_handle(object, globjhdl2 + GLAPI_UUID_LENGTH,
                                        GFAPI_HANDLE_LENGTH);
            LOG_ERR("glfs_h_extract_handle", (ret != 16));

            if (memcmp(globjhdl + GLAPI_UUID_LENGTH,
                       globjhdl2 + GLAPI_UUID_LENGTH, 16)) {
                fprintf(stderr, "Error: gfid mismatch\n");
                exit(1);
            }
            upcall_received = 1;
        }

    retry:
        if (!upcall_received)
            sleep(1); /* glfs_h_poll_upcall() does not block */

        if (!ret) {
            glfs_free(cbk);
            cbk = NULL;
        }
    }

    if (!upcall_received) {
        fprintf(stderr, "Error: Upcall not received\n");
        exit(1);
    }

    ret = glfs_fini(fs);
    LOG_ERR("glfs_fini", ret);

    fprintf(stderr, "End of libgfapi_fini\n");

    exit(0);
}
Example #13
0
int
main (int argc, char *argv[])
{
        glfs_t    *fs       = NULL;
        int       ret       = 0;
        int       i         = 0;
        glfs_fd_t *fd       = NULL;
        glfs_fd_t *fd1      = NULL;
        char      *topdir   = "topdir", *filename = "file1";
        char      *buf      = NULL;
        char      *logfile  = NULL;

        if (argc != 3) {
                fprintf (stderr,
                        "Expect following args %s <Vol> <log file>\n"
                        , argv[0]);
                return -1;
        }

        logfile = argv[2];

        for (i = 0; i < TEST_CASE_LOOP; i++) {
                fs = glfs_new (argv[1]);
                if (!fs) {
                        fprintf (stderr, "glfs_new: returned NULL (%s)\n",
                                strerror (errno));
                        return -1;
                }

                ret = glfs_set_volfile_server (fs, "tcp", "localhost", 24007);
                if (ret < 0) {
                        fprintf (stderr, "glfs_set_volfile_server failed ret:%d (%s)\n",
                        ret, strerror (errno));
                        return -1;
                }

                ret = glfs_set_logging (fs, logfile, 7);
                if (ret < 0) {
                        fprintf (stderr, "glfs_set_logging failed with ret: %d (%s)\n",
                                ret, strerror (errno));
                        return -1;
                }

                ret = glfs_init (fs);
                if (ret < 0) {
                        fprintf (stderr, "glfs_init failed with ret: %d (%s)\n",
                                ret, strerror (errno));
                        return -1;
                }

                ret = large_number_of_fops (fs);
                if (ret < 0)
                        return -1;

                ret = large_read_write (fs);
                if (ret < 0)
                        return -1;

                ret = volfile_change (argv[1]);
                if (ret < 0)
                        return -1;

                ret = large_number_of_fops (fs);
                if (ret < 0)
                        return -1;

                ret = large_read_write (fs);
                if (ret < 0)
                        return -1;

                ret = glfs_fini (fs);
                if (ret < 0) {
                        fprintf (stderr, "glfs_fini failed with ret: %d (%s)\n",
                                ret, strerror (errno));
                        return -1;
                }
        }
        return 0;
}
Example #14
0
int
main (int argc, char *argv[])
{
        glfs_t    *fs = NULL;
        glfs_t    *fs2 = NULL;
        int        ret = 0, i;
        glfs_fd_t *fd = NULL;
        char      *filename = "/a1";
        char      *filename2 = "/a2";
        struct     stat sb = {0, };
        struct    glfs_callback_arg cbk;
        char      *logfile = NULL;
        char      *volname = NULL;
        int        cnt = 1;
        int       upcall_received = 0;
        struct glfs_callback_inode_arg *in_arg = NULL;
        struct glfs_object *root = NULL, *leaf = NULL;
        unsigned char   globjhdl[GFAPI_HANDLE_LENGTH];
        unsigned char   globjhdl2[GFAPI_HANDLE_LENGTH];

        cbk.reason = 0;

        fprintf (stderr, "Starting libgfapi_fini\n");
        if (argc != 3) {
                fprintf (stderr, "Invalid argument\n");
                exit(1);
        }

        volname = argv[1];
        logfile = argv[2];


        fs = glfs_new (volname);
        if (!fs) {
                fprintf (stderr, "glfs_new: returned NULL\n");
                return 1;
        }

        ret = glfs_set_volfile_server (fs, "tcp", "localhost", 24007);
        LOG_ERR("glfs_set_volfile_server", ret);

        ret = glfs_set_logging (fs, logfile, 7);
        LOG_ERR("glfs_set_logging", ret);

        ret = glfs_init (fs);
        LOG_ERR("glfs_init", ret);

        fs2 = glfs_new (volname);
        if (!fs) {
                fprintf (stderr, "glfs_new: returned NULL\n");
                return 1;
        }

        ret = glfs_set_volfile_server (fs2, "tcp", "localhost", 24007);
        LOG_ERR("glfs_set_volfile_server", ret);

        ret = glfs_set_logging (fs2, logfile, 7);
        LOG_ERR("glfs_set_logging", ret);

        ret = glfs_init (fs2);
        LOG_ERR("glfs_init", ret);

        sleep (2);
        root = glfs_h_lookupat (fs, NULL, "/", &sb, 0);
        if (!root) {
                ret = -1;
                LOG_ERR ("glfs_h_lookupat root", ret);
        }
        leaf = glfs_h_lookupat (fs, root, filename, &sb, 0);
        if (!leaf) {
                ret = -1;
                LOG_IF_NO_ERR ("glfs_h_lookupat leaf", ret);
        }

        root = glfs_h_lookupat (fs2, NULL, "/", &sb, 0);
        if (!root) {
                ret = -1;
                LOG_ERR ("glfs_h_lookupat root", ret);
        }
        leaf = glfs_h_creat (fs2, root, filename, O_RDWR, 0644, &sb);
        if (!leaf) {
                ret = -1;
                LOG_ERR ("glfs_h_lookupat leaf", ret);
        }
        fprintf (stderr, "glfs_h_create leaf - %p\n", leaf);

        while (cnt++ < 5) {
                ret = glfs_h_poll_upcall(fs, &cbk);
                LOG_ERR ("glfs_h_poll_upcall", ret);

                if (cbk.reason == GFAPI_INODE_INVALIDATE) {
                        fprintf (stderr, "Upcall received(%d)\n",
                                 cbk.reason);
                        in_arg = (struct glfs_callback_inode_arg *)(cbk.event_arg);

                        ret = glfs_h_extract_handle (root,
                                                     globjhdl+GLAPI_UUID_LENGTH,
                                                     GFAPI_HANDLE_LENGTH);
                        LOG_ERR("glfs_h_extract_handle", (ret != 16));

                        ret = glfs_h_extract_handle (in_arg->object,
                                                  globjhdl2+GLAPI_UUID_LENGTH,
                                                  GFAPI_HANDLE_LENGTH);
                        LOG_ERR("glfs_h_extract_handle", (ret != 16));

                        if (memcmp (globjhdl+GLAPI_UUID_LENGTH,
                                    globjhdl2+GLAPI_UUID_LENGTH, 16)) {
                                fprintf (stderr, "Error: gfid mismatch\n");
                                exit (1);
                        }
                        upcall_received = 1;
                }
        }

        if (!upcall_received) {
                fprintf (stderr, "Error: Upcall not received\n");
                exit (1);
        }

        ret = glfs_fini(fs);
        LOG_ERR("glfs_fini", ret);

        fprintf (stderr, "End of libgfapi_fini\n");

        exit(0);
}
Example #15
0
int
main (int argc, char *argv[])
{
	glfs_t    *fs = NULL;
	glfs_t    *fs2 = NULL;
	int        ret = 0;
	glfs_fd_t *fd = NULL;
	glfs_fd_t *fd2 = NULL;
	struct stat sb = {0, };
	char       readbuf[32];
	char       writebuf[32];

	char      *filename = "/filename2";

	fs = glfs_new ("fsync");
	if (!fs) {
		fprintf (stderr, "glfs_new: returned NULL\n");
		return 1;
	}

//	ret = glfs_set_volfile (fs, "/tmp/posix.vol");

	ret = glfs_set_volfile_server (fs, "tcp", "localhost", 24007);

//	ret = glfs_set_volfile_server (fs, "unix", "/tmp/gluster.sock", 0);

	ret = glfs_set_logging (fs, "/dev/stderr", 7);

	ret = glfs_init (fs);

	fprintf (stderr, "glfs_init: returned %d\n", ret);

	sleep (2);

	fs2 = glfs_new ("fsync");
	if (!fs2) {
		fprintf (stderr, "glfs_new: returned NULL\n");
		return 1;
	}


//	ret = glfs_set_volfile (fs2, "/tmp/posix.vol");

	ret = glfs_set_volfile_server (fs2, "tcp", "localhost", 24007);

	ret = glfs_set_logging (fs2, "/dev/stderr", 7);

	ret = glfs_init (fs2);

	fprintf (stderr, "glfs_init: returned %d\n", ret);

	ret = glfs_lstat (fs, filename, &sb);
	fprintf (stderr, "%s: (%d) %s\n", filename, ret, strerror (errno));

	fd = glfs_creat (fs, filename, O_RDWR, 0644);
	fprintf (stderr, "%s: (%p) %s\n", filename, fd, strerror (errno));

	fd2 = glfs_open (fs2, filename, O_RDWR);
	fprintf (stderr, "%s: (%p) %s\n", filename, fd, strerror (errno));

	sprintf (writebuf, "hi there\n");
	ret = glfs_write (fd, writebuf, 32, 0);

	glfs_lseek (fd2, 0, SEEK_SET);

	ret = glfs_read (fd2, readbuf, 32, 0);

	printf ("read %d, %s", ret, readbuf);

	glfs_close (fd);
	glfs_close (fd2);

	filename = "/filename3";
	ret = glfs_mknod (fs, filename, S_IFIFO, 0);
	fprintf (stderr, "%s: (%d) %s\n", filename, ret, strerror (errno));

	ret = glfs_lstat (fs, filename, &sb);
	fprintf (stderr, "%s: (%d) %s\n", filename, ret, strerror (errno));


	ret = glfs_rename (fs, filename, "/filename4");
	fprintf (stderr, "rename(%s): (%d) %s\n", filename, ret,
		 strerror (errno));

	ret = glfs_unlink (fs, "/filename4");
	fprintf (stderr, "unlink(%s): (%d) %s\n", "/filename4", ret,
		 strerror (errno));

	filename = "/dirname2";
	ret = glfs_mkdir (fs, filename, 0);
	fprintf (stderr, "%s: (%d) %s\n", filename, ret, strerror (errno));

	ret = glfs_lstat (fs, filename, &sb);
	fprintf (stderr, "lstat(%s): (%d) %s\n", filename, ret, strerror (errno));

	ret = glfs_rmdir (fs, filename);
	fprintf (stderr, "rmdir(%s): (%d) %s\n", filename, ret, strerror (errno));

	test_dirops (fs);

	test_xattr (fs);

	test_chdir (fs);

	// done

	glfs_fini (fs);
	glfs_fini (fs2);

	return ret;
}
int
main (int argc, char *argv[])
{
        glfs_t    *fs = NULL;
        glfs_t    *fs2 = NULL;
        glfs_t    *fs_tmp = NULL;
        glfs_t    *fs_tmp2 = NULL;
        int        ret = 0, i;
        glfs_fd_t *fd = NULL;
        glfs_fd_t *fd2 = NULL;
        glfs_fd_t *fd_tmp = NULL;
        glfs_fd_t *fd_tmp2 = NULL;
        char       readbuf[32];
        char      *filename = "file_tmp";
        char      *writebuf = NULL;
        char      *vol_id  = NULL;
        unsigned int       cnt = 1;
        struct    callback_arg cbk;
        char      *logfile = NULL;
        char      *volname = NULL;

        cbk.object = NULL;

        if (argc != 3) {
                fprintf (stderr, "Invalid argument\n");
                exit(1);
        }

        volname = argv[1];
        logfile = argv[2];

        fs = glfs_new (volname);
        if (!fs) {
                fprintf (stderr, "glfs_new: returned NULL\n");
                return -1;
        }

        ret = glfs_set_volfile_server (fs, "tcp", "localhost", 24007);
        LOG_ERR("glfs_set_volfile_server", ret);

        ret = glfs_set_logging (fs, logfile, 7);
        LOG_ERR("glfs_set_logging", ret);

        ret = glfs_init (fs);
        LOG_ERR("glfs_init", ret);

        fs2 = glfs_new (volname);
        if (!fs2) {
                fprintf (stderr, "glfs_new fs2: returned NULL\n");
                return 1;
        }

        ret = glfs_set_volfile_server (fs2, "tcp", "localhost", 24007);
        LOG_ERR("glfs_set_volfile_server-fs2", ret);

        ret = glfs_set_logging (fs2, logfile, 7);
        LOG_ERR("glfs_set_logging-fs2", ret);

        ret = glfs_init (fs2);
        LOG_ERR("glfs_init-fs2", ret);

        fd = glfs_creat(fs, filename, O_RDWR|O_SYNC, 0644);
        if (fd <= 0) {
                ret = -1;
                LOG_ERR ("glfs_creat", ret);
        }
        fprintf (stderr, "glfs-create fd - %d\n", fd);

        fd2 = glfs_open(fs2, filename, O_SYNC|O_RDWR|O_CREAT);
        if (fd2 <= 0) {
                ret = -1;
                LOG_ERR ("glfs_open-fs2", ret);
        }
        fprintf (stderr, "glfs-open fd2 - %d\n", fd2);

        do {
                if (cnt%2) {
                        fd_tmp = fd;
                        fs_tmp = fs;
                        fd_tmp2 = fd2;
                        fs_tmp2 = fs2;
                } else {
                        fd_tmp = fd2;
                        fs_tmp = fs2;
                        fd_tmp2 = fd;
                        fs_tmp2 = fs;
                }

                /* WRITE on fd_tmp */
                writebuf = malloc(10);
                if (writebuf) {
                        memcpy (writebuf, "abcd", 4);
                        ret = glfs_write (fd_tmp, writebuf, 4, 0);
                        if (ret <= 0)   {
                                ret = -1;
                                LOG_ERR ("glfs_write", ret);
                        } else {
                                fprintf (stderr,
                                         "glfs_write suceeded\n");
                        }
                        free(writebuf);
                } else {
                        fprintf (stderr,
                                 "Could not allocate writebuf\n");
                        return -1;
                }

                /* READ on fd_tmp2 */
                ret = glfs_lseek (fd_tmp2, 0, SEEK_SET);
                LOG_ERR ("glfs_lseek", ret);

                ret = glfs_pread (fd_tmp2, readbuf, 4, 0, 0);

                if (ret <= 0) {
                        ret = -1;
                        LOG_ERR ("glfs_pread", ret);
                } else {
                        fprintf (stderr, "glfs_read: %s\n", readbuf);
                }

                /* Open() fops seem to be not performed on server side until
                 * there are I/Os on that fd
                 */
                if (cnt > 2) {
                        ret = glfs_h_poll_upcall(fs_tmp, &cbk);
                        LOG_ERR ("glfs_h_poll_upcall", ret);
                        if (cbk.object) {
                                fprintf (stderr, " upcall event type - %d,"
                                                 " flags - %d, expire_time_attr - %d\n" ,
                                         cbk.reason, cbk.flags, cbk.expire_time_attr);
                        } else {
                                fprintf (stderr,
                                         "Dint receive upcall notify event");
                                ret = -1;
                                goto err;
                        }
                }

                sleep(5);
        } while (++cnt < 5);

err:
        glfs_close(fd);
        LOG_ERR ("glfs_close", ret);

        glfs_close(fd2);
        LOG_ERR ("glfs_close-fd2", ret);

out:
        if (fs) {
                ret = glfs_fini(fs);
                fprintf (stderr, "glfs_fini(fs) returned %d \n", ret);
        }

        if (fs2) {
                ret = glfs_fini(fs2);
                fprintf (stderr, "glfs_fini(fs2) returned %d \n", ret);
        }

        if (ret)
                exit(1);
        exit(0);
}
Example #17
0
int
main (int argc, char *argv[])
{
        int                     ret            = 0;
        glfs_t                  *fs            = NULL;
        struct glfs_object      *root = NULL, *file_obj = NULL;
        struct stat             sb             = {0, };
        char                    readbuf[32], writebuf[32];
        char                    *filename      = "file.txt";
        char                    *logfile       = NULL;
        char                    *volname       = NULL;
        char                    *hostname      = NULL;

        if (argc != 4) {
                fprintf (stderr, "Invalid argument\n");
                exit(1);
        }

        hostname = argv[1];
        volname = argv[2];
        logfile = argv[3];

        fs = glfs_new (volname);
        if (!fs) {
                fprintf (stderr, "glfs_new: returned NULL\n");
                ret = -1;
        }

        ret = glfs_set_volfile_server (fs, "tcp", hostname, 24007);
        LOG_ERR("glfs_set_volfile_server", ret);

        ret = glfs_set_logging (fs, logfile, 7);
        LOG_ERR("glfs_set_logging", ret);

        ret = glfs_init (fs);
        LOG_ERR("glfs_init", ret);

        root = glfs_h_lookupat (fs, NULL, "/", &sb, 0);
        if (root == NULL) {
                fprintf (stderr, "glfs_h_lookupat: error on lookup of / ,%s\n",
                         strerror (errno));
                goto out;
        }

        file_obj = glfs_h_creat (fs, root, filename, O_CREAT, 0644, &sb);
        if (file_obj == NULL) {
                fprintf (stderr, "glfs_h_creat: error on create of %s: from (%p),%s\n",
                         filename, root, strerror (errno));
                goto out;
        }

        /* test read/write based on anonymous fd */
        memcpy (writebuf, "abcdefghijklmnopqrstuvwxyz012345", 32);

        ret = glfs_h_anonymous_write (fs, file_obj, writebuf, 32, 0);
        if (ret < 0)
                LOG_ERR ("glfs_h_anonymous_write", ret);

        ret = glfs_h_anonymous_read (fs, file_obj, readbuf, 32, 0);
        if (ret < 0)
                LOG_ERR ("glfs_h_anonymous_read", ret);

        if (memcmp (readbuf, writebuf, 32)) {
                fprintf (stderr, "Failed to read what I wrote: %s %s\n", readbuf,
                         writebuf);
                ret = -1;
                goto out;
        }

        ret = 0;
out:
        if (file_obj)
                glfs_h_close (file_obj);

        if (fs) {
                ret = glfs_fini(fs);
                fprintf (stderr, "glfs_fini(fs) returned %d \n", ret);
        }
        if (ret)
                exit(1);
        exit(0);
}
Example #18
0
int
main(int argc, char *argv[])
{
    glfs_t *fs = NULL;
    int ret = 0;
    glfs_fd_t *fd = NULL;
    char *filename = NULL;
    char *logfile = NULL;
    char *host = NULL;

    if (argc != 5) {
        return -1;
    }

    host = argv[2];
    logfile = argv[3];
    filename = argv[4];

    /* setup signal handler for exiting */
    signal(SIGTERM, stop_running);

    fs = glfs_new(argv[1]);
    if (!fs) {
        return -1;
    }

    ret = glfs_set_volfile_server(fs, "tcp", host, 24007);
    if (ret < 0) {
        return -1;
    }

    ret = glfs_set_logging(fs, logfile, 7);
    if (ret < 0) {
        return -1;
    }

    ret = glfs_init(fs);
    if (ret < 0) {
        return -1;
    }

    fd = glfs_creat(fs, filename, O_RDWR, 0644);
    if (!fd) {
        return -1;
    }

    /* sleep until SIGTERM has been received */
    while (keep_running) {
        sleep(1);
    }

    ret = glfs_close(fd);
    if (ret < 0) {
        return -1;
    }

    ret = glfs_fini(fs);
    if (ret < 0) {
        return -1;
    }

    return 0;
}
Example #19
0
bool GlusterBackend::initialize(GlusterFSConnection _connectionInfo) {
  this->connectionInfo= _connectionInfo;

  //Create
  fs = glfs_new(connectionInfo.volumeName.c_str());
  if(fs==nullptr){
    LOG(ERROR)<<"Error in creating GlusterFS instance.";
    return false;
  }
  //Set volume server
  /**
   *
   * NOTE: This API is special, multiple calls to this function with different
   *  volfile servers, port or transport-type would create a list of volfile
   *  servers which would be polled during `volfile_fetch_attempts()
   *
   * @transport: String specifying the transport used to connect to the
   *  management daemon. Specifying NULL will result in the usage
   *  of the default (tcp) transport type. Permitted values
   *  are those what you specify as transport-type in a volume
   *  specification file (e.g "tcp", "rdma" etc.)
   *
   *  0 : Success.
   * -1 : Failure. @errno will be set with the type of failure.
   **/
  bool allFailed = true;
  for(VolumeServer &volServer:_connectionInfo.volumeServers){
    int ret = glfs_set_volfile_server ((glfs_t*)fs, volServer.transport.c_str(), volServer.serverIP.c_str(), volServer.port);
    //int ret = glfs_set_volfile_server ((glfs_t*)fs, volServer.transport.c_str(), volServer.serverIP.c_str(), 23432);
    //int ret = glfs_set_volfile_server ((glfs_t*)fs, volServer.transport.c_str(), volServer.serverIP.c_str(), );
    if(ret !=0){
      glfs_unset_volfile_server((glfs_t*)fs, volServer.transport.c_str(), volServer.serverIP.c_str(), volServer.port);
      LOG(ERROR)<<"Error in connecting to VolumeServer:"<<volServer.serverIP
          <<":"<<volServer.port<<"("<<volServer.transport<<")"<<" ErrorCode:"<<ret;
    } else
      allFailed = false;
  }

  if(allFailed){
    LOG(ERROR)<<"Couldn't connect to any of Volume Servers. Gluster Initialization failed.";
    glfs_fini((glfs_t*)fs);
    return false;
  }

  //Set Logging info
  if(glfs_set_logging ((glfs_t*)fs, "/dev/stderr", 5)!=0)
    LOG(ERROR)<<"Failed to set logging for GlusterFS.";

  int ret = glfs_init((glfs_t*)fs);
  if(ret!=0){
    LOG(ERROR)<<"Failed to initialize GlusterFS. ErrorCode:"<<ret;
    glfs_fini((glfs_t*)fs);
    return false;
  }

  LOG(INFO)<<"GlusterFS backend initialized for Volume:"<<this->connectionInfo.volumeName;
  /*vector<BackendItem> tmp;
  list(tmp);*/

  return true;
}
Example #20
0
int
main (int argc, char *argv[])
{
        glfs_t    *fs = NULL;
        int        ret = 0, i;
        glfs_fd_t *fd = NULL;
        char      *filename = "/a1";
        char      *filename2 = "/a2";
        struct     stat sb = {0, };
        struct    callback_arg cbk;
        char      *logfile = NULL;
        char      *volname = NULL;
        int       cnt = 1;
        struct callback_inode_arg *in_arg = NULL;
        struct glfs_object *root = NULL, *leaf = NULL;

        cbk.reason = 0;

        fprintf (stderr, "Starting libgfapi_fini\n");
        if (argc != 3) {
                fprintf (stderr, "Invalid argument\n");
                exit(1);
        }

        volname = argv[1];
        logfile = argv[2];


        fs = glfs_new (volname);
        if (!fs) {
                fprintf (stderr, "glfs_new: returned NULL\n");
                return 1;
        }

        ret = glfs_set_volfile_server (fs, "tcp", "localhost", 24007);
        LOG_ERR("glfs_set_volfile_server", ret);

        ret = glfs_set_logging (fs, logfile, 7);
        LOG_ERR("glfs_set_logging", ret);

        ret = glfs_init (fs);
        LOG_ERR("glfs_init", ret);

        sleep (2);
        root = glfs_h_lookupat (fs, NULL, "/", &sb, 0);
        if (!root) {
                ret = -1;
                LOG_ERR ("glfs_h_lookupat root", ret);
        }
        leaf = glfs_h_lookupat (fs, root, filename, &sb, 0);
        if (!leaf) {
                ret = -1;
                LOG_IF_NO_ERR ("glfs_h_lookupat leaf", ret);
        }

        leaf = glfs_h_creat (fs, root, filename, O_RDWR, 0644, &sb);
        if (!leaf) {
                ret = -1;
                LOG_ERR ("glfs_h_lookupat leaf", ret);
        }
        fprintf (stderr, "glfs_h_create leaf - %p\n", leaf);

        leaf = glfs_h_lookupat (fs, root, filename2, &sb, 0);
        if (!leaf) {
                ret = -1;
                LOG_IF_NO_ERR ("glfs_h_lookupat leaf", ret);
        }

        ret = glfs_h_rename (fs, root, filename, root, filename2);
        LOG_ERR("glfs_rename", ret);

        while (cnt++ < 5) {
                ret = glfs_h_poll_upcall(fs, &cbk);
                LOG_ERR ("glfs_h_poll_upcall", ret);

                /* There should not be any upcalls sent */
                if (cbk.reason != GFAPI_CBK_EVENT_NULL) {
                        fprintf (stderr, "Error: Upcall received(%d)\n",
                                 cbk.reason);
                        exit (1);
                }
        }

        ret = glfs_fini(fs);
        LOG_ERR("glfs_fini", ret);

        fprintf (stderr, "End of libgfapi_fini\n");

        exit(0);
}
Example #21
0
int
main(int argc, char *argv[])
{
    int ret = -1;
    glfs_t *fs = NULL;
    char *volname = NULL;
    char *logfile = NULL;
    char *hostname = NULL;
    char *my_file = "file_";
    char my_file_name[MAXPATHNAME];
    uint32_t flags = O_RDWR | O_SYNC;
    struct glfs_fd *fd = NULL;
    int i = 0;
    int pct = 0;
    struct timespec timestamp = {0, 0}, st_timestamp, ed_timestamp;
    struct timespec otimestamp = {0, 0}, ost_timestamp, oed_timestamp;

    if (argc != 4) {
        fprintf(stderr, "Invalid argument\n");
        return 1;
    }

    hostname = argv[1];
    volname = argv[2];
    logfile = argv[3];

    fs = glfs_new(volname);
    VALIDATE_BOOL_AND_GOTO_LABEL_ON_ERROR("glfs_new", !!fs, ret, out);

    ret = glfs_set_volfile_server(fs, "tcp", hostname, 24007);
    VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_set_volfile_server", ret, out);

    ret = glfs_set_logging(fs, logfile, 7);
    VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_set_logging", ret, out);

    ret = glfs_init(fs);
    VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_init", ret, out);

    for (i = 0; i < MAX_FILES_CREATE; i++) {
        sprintf(my_file_name, "%s%d", my_file, i);

        fd = glfs_creat(fs, my_file_name, flags, 0644);
        VALIDATE_BOOL_AND_GOTO_LABEL_ON_ERROR("glfs_creat", !!fd, ret, out);

        glfs_close(fd);
    }

    /* measure performance using old readdir call and new xreaddirplus call and
     * compare */
    ret = clock_gettime(CLOCK_REALTIME, &ost_timestamp);
    VALIDATE_AND_GOTO_LABEL_ON_ERROR("clock_gettime", ret, out);

    ret = old_readdir(fs);
    VALIDATE_AND_GOTO_LABEL_ON_ERROR("old_readdir", ret, out);

    ret = clock_gettime(CLOCK_REALTIME, &oed_timestamp);
    VALIDATE_AND_GOTO_LABEL_ON_ERROR("clock_gettime", ret, out);

    assimilatetime(&otimestamp, ost_timestamp, oed_timestamp);

    printf("\tOverall time using readdir:\n\t\tSecs:%ld\n\t\tnSecs:%ld\n",
           otimestamp.tv_sec, otimestamp.tv_nsec);

    ret = clock_gettime(CLOCK_REALTIME, &st_timestamp);
    VALIDATE_AND_GOTO_LABEL_ON_ERROR("clock_gettime", ret, out);

    ret = new_xreaddirplus(fs);
    VALIDATE_AND_GOTO_LABEL_ON_ERROR("new_xreaddirplus", ret, out);

    ret = clock_gettime(CLOCK_REALTIME, &ed_timestamp);
    VALIDATE_AND_GOTO_LABEL_ON_ERROR("clock_gettime", ret, out);

    assimilatetime(&timestamp, st_timestamp, ed_timestamp);

    printf("\tOverall time using xreaddirplus:\n\t\tSecs:%ld\n\t\tnSecs:%ld\n",
           timestamp.tv_sec, timestamp.tv_nsec);

    pct = comparetime(otimestamp, timestamp);
    printf("There is improvement by %d%%\n", pct);

    ret = 0;
out:
    if (fs) {
        ret = glfs_fini(fs);
        if (ret)
            fprintf(stderr, "glfs_fini(fs) returned %d\n", ret);
    }

    return ret;
}
int
main (int argc, char *argv[])
{
        glfs_t                   *fs = NULL;
        glfs_t                   *fs2 = NULL;
        glfs_t                   *fs_tmp = NULL;
        glfs_t                   *fs_tmp2 = NULL;
        int                       ret = 0, i;
        glfs_fd_t                *fd = NULL;
        glfs_fd_t                *fd2 = NULL;
        glfs_fd_t                *fd_tmp = NULL;
        glfs_fd_t                *fd_tmp2 = NULL;
        char                      readbuf[32];
        char                     *filename = "file_tmp";
        char                     *writebuf = NULL;
        char                     *vol_id  = NULL;
        unsigned int              cnt = 1;
        struct glfs_upcall       *cbk = NULL;
        char                     *logfile = NULL;
        char                     *volname = NULL;
        char                     *hostname = NULL;

        if (argc != 4) {
                fprintf (stderr, "Invalid argument\n");
                exit(1);
        }

        hostname = argv[1];
        volname = argv[2];
        logfile = argv[3];

        fs = glfs_new (volname);
        if (!fs) {
                fprintf (stderr, "glfs_new: returned NULL\n");
                return -1;
        }

        ret = glfs_set_volfile_server (fs, "tcp", hostname, 24007);
        LOG_ERR("glfs_set_volfile_server", ret);

        ret = glfs_set_logging (fs, logfile, 7);
        LOG_ERR("glfs_set_logging", ret);

        ret = glfs_init (fs);
        LOG_ERR("glfs_init", ret);

        /* This does not block, but enables caching of events. Real
         * applications like NFS-Ganesha run this in a thread before activity
         * on the fs (through this instance) happens. */
        ret = glfs_h_poll_upcall(fs_tmp, &cbk);
        LOG_ERR ("glfs_h_poll_upcall", ret);

        fs2 = glfs_new (volname);
        if (!fs2) {
                fprintf (stderr, "glfs_new fs2: returned NULL\n");
                return 1;
        }

        ret = glfs_set_volfile_server (fs2, "tcp", hostname, 24007);
        LOG_ERR("glfs_set_volfile_server-fs2", ret);

        ret = glfs_set_logging (fs2, logfile, 7);
        LOG_ERR("glfs_set_logging-fs2", ret);

        ret = glfs_init (fs2);
        LOG_ERR("glfs_init-fs2", ret);

        fd = glfs_creat(fs, filename, O_RDWR|O_SYNC, 0644);
        if (fd <= 0) {
                ret = -1;
                LOG_ERR ("glfs_creat", ret);
        }
        fprintf (stderr, "glfs-create fd - %d\n", fd);

        fd2 = glfs_open(fs2, filename, O_SYNC|O_RDWR|O_CREAT);
        if (fd2 <= 0) {
                ret = -1;
                LOG_ERR ("glfs_open-fs2", ret);
        }
        fprintf (stderr, "glfs-open fd2 - %d\n", fd2);

        do {
                if (cnt%2) {
                        fd_tmp = fd;
                        fs_tmp = fs;
                        fd_tmp2 = fd2;
                        fs_tmp2 = fs2;
                } else {
                        fd_tmp = fd2;
                        fs_tmp = fs2;
                        fd_tmp2 = fd;
                        fs_tmp2 = fs;
                }

                /* WRITE on fd_tmp */
                writebuf = malloc(10);
                if (writebuf) {
                        memcpy (writebuf, "abcd", 4);
                        ret = glfs_write (fd_tmp, writebuf, 4, 0);
                        if (ret <= 0)   {
                                ret = -1;
                                LOG_ERR ("glfs_write", ret);
                        } else {
                                fprintf (stderr,
                                         "glfs_write suceeded\n");
                        }
                        free(writebuf);
                } else {
                        fprintf (stderr,
                                 "Could not allocate writebuf\n");
                        return -1;
                }

                /* READ on fd_tmp2 */
                ret = glfs_lseek (fd_tmp2, 0, SEEK_SET);
                LOG_ERR ("glfs_lseek", ret);

                memset (readbuf, 0, sizeof(readbuf));
                ret = glfs_pread (fd_tmp2, readbuf, 4, 0, 0, NULL);

                if (ret <= 0) {
                        ret = -1;
                        LOG_ERR ("glfs_pread", ret);
                } else {
                        fprintf (stderr, "glfs_read: %s\n", readbuf);
                }

                /* Open() fops seem to be not performed on server side until
                 * there are I/Os on that fd
                 */
                if (cnt > 2) {
                        struct glfs_upcall_inode *in_arg = NULL;
                        enum glfs_upcall_reason   reason = 0;
                        struct glfs_object       *object = NULL;
                        uint64_t                  flags = 0;
                        uint64_t                  expire = 0;

                        ret = glfs_h_poll_upcall(fs_tmp, &cbk);
                        LOG_ERR ("glfs_h_poll_upcall", ret);

                        reason = glfs_upcall_get_reason (cbk);

                        /* Expect 'GLFS_INODE_INVALIDATE' upcall event. */
                        if (reason == GLFS_UPCALL_INODE_INVALIDATE) {
                                in_arg = glfs_upcall_get_event (cbk);

                                object = glfs_upcall_inode_get_object (in_arg);
                                flags = glfs_upcall_inode_get_flags (in_arg);
                                expire = glfs_upcall_inode_get_expire (in_arg);

                                fprintf (stderr, " upcall event type - %d,"
                                         " object(%p), flags(%d), "
                                         " expire_time_attr(%d)\n" ,
                                         reason, object, flags, expire);
                        } else {
                                fprintf (stderr,
                                         "Didnt receive upcall notify event");
                                ret = -1;
                                goto err;
                        }

                        glfs_free (cbk);
                }

                sleep(5);
        } while (++cnt < 5);

err:
        glfs_close(fd);
        LOG_ERR ("glfs_close", ret);

        glfs_close(fd2);
        LOG_ERR ("glfs_close-fd2", ret);

out:
        if (fs) {
                ret = glfs_fini(fs);
                fprintf (stderr, "glfs_fini(fs) returned %d \n", ret);
        }

        if (fs2) {
                ret = glfs_fini(fs2);
                fprintf (stderr, "glfs_fini(fs2) returned %d \n", ret);
        }

        if (ret)
                exit(1);
        exit(0);
}
Example #23
0
int
main (int argc, char **argv)
{
        glfs_t  *fs;
        int     ret;
        int     meta_fd         = (-1);
        char    *meta_buf       = NULL;
        int     data_fd         = (-1);
        char    *data_buf       = NULL;

        fs = glfs_new ("whocares");
        if (!fs) {
                fprintf (stderr, "glfs_new failed\n");
                return EXIT_FAILURE;
        }

        if (getenv("RECON_DEBUG")) {
                ret = glfs_set_logging (fs, "/dev/stderr", 7);
        }
        else {
                ret = glfs_set_logging (fs, "/dev/null", 0);
        }

        if (ret != GFAPI_SUCCESS) {
                fprintf (stderr, "glfs_set_logging failed (%d)\n", errno);
                return EXIT_FAILURE;
        }

        ret = glfs_set_volfile (fs, argv[1]);
        if (ret != GFAPI_SUCCESS) {
                fprintf (stderr, "glfs_set_volfile failed (%d)\n", errno);
                return EXIT_FAILURE;
        }

        ret = glfs_init (fs);
        if (ret != GFAPI_SUCCESS) {
                fprintf (stderr, "glfs_init failed (%d)\n", errno);
                return EXIT_FAILURE;
        }

        meta_fd = open (argv[2], O_RDONLY);
        if (meta_fd < 0) {
                perror ("open");
                return EXIT_FAILURE;
        }

        /* TBD: get proper length */
        meta_buf = mmap (NULL, 1048576, PROT_READ, MAP_PRIVATE, meta_fd, 0);
        if (meta_buf == MAP_FAILED) {
                perror ("mmap");
                return EXIT_FAILURE;
        }

        data_fd = open (argv[3], O_RDONLY);
        if (data_fd < 0) {
                perror ("open");
                return EXIT_FAILURE;
        }

        /* TBD: get proper length */
        data_buf = mmap (NULL, 1048576, PROT_READ, MAP_PRIVATE, data_fd, 0);
        if (data_buf == MAP_FAILED) {
                perror ("mmap");
                return EXIT_FAILURE;
        }

        for (;;) {
                if (!recon_execute(fs,&meta_buf,&data_buf)) {
                        break;
                }
        }

        return EXIT_SUCCESS;
}
Example #24
0
int
main (int argc, char *argv[])
{
    int             ret = -1;
    int             flags = O_RDWR|O_SYNC;
    glfs_t         *fs = NULL;
    glfs_fd_t      *fd1 = NULL;
    char           *volname = NULL;
    char           *logfile = NULL;
    const char     *filename = "file_tmp";
    const char     buff[WRITE_SIZE];
    struct stat    sb;

    if (argc != 3) {
        fprintf (stderr, "Invalid argument\n");
        return 1;
    }

    volname = argv[1];
    logfile = argv[2];

    fs = glfs_new (volname);
    if (!fs)
        VALIDATE_AND_GOTO_LABEL_ON_ERROR ("glfs_new", ret, out);

    ret = glfs_set_volfile_server (fs, "tcp", "localhost", 24007);
    VALIDATE_AND_GOTO_LABEL_ON_ERROR ("glfs_set_volfile_server", ret, out);

    ret = glfs_set_logging (fs, logfile, 7);
    VALIDATE_AND_GOTO_LABEL_ON_ERROR ("glfs_set_logging", ret, out);

    ret = glfs_init (fs);
    VALIDATE_AND_GOTO_LABEL_ON_ERROR ("glfs_init", ret, out);

    fd1 = glfs_creat(fs, filename, flags, 0644);
    if (fd1 == NULL) {
        ret = -1;
        VALIDATE_AND_GOTO_LABEL_ON_ERROR ("glfs_creat", ret, out);
    }

    ret = glfs_write (fd1, buff, WRITE_SIZE, flags);
    VALIDATE_AND_GOTO_LABEL_ON_ERROR ("glfs_write", ret, out);

    ret = glfs_truncate (fs, filename, TRUNC_SIZE);
    VALIDATE_AND_GOTO_LABEL_ON_ERROR ("glfs_truncate", ret, out);

    ret = glfs_fstat (fd1, &sb);
    VALIDATE_AND_GOTO_LABEL_ON_ERROR ("glfs_fstat", ret, out);

    if (sb.st_size != TRUNC_SIZE) {
        fprintf (stderr, "wrong size %jd should be %jd\n",
                 (intmax_t)sb.st_size, (intmax_t)2048);
        ret = -1;
    }

out:
    if (fd1 != NULL)
        glfs_close(fd1);
    if (fs) {
        /*
         * If this fails (as it does on Special Snowflake NetBSD for no
         * good reason), it shouldn't affect the result of the test.
         */
        (void) glfs_fini(fs);
    }

    return ret;
}
Example #25
0
int
main (int argc, char *argv[])
{
        glfs_t *fs;
        int ret;

        program_invocation_name = basename (argv[0]);
        atexit (close_stdout);

        state = init_state ();
        if (state == NULL) {
                error (0, errno, "failed to initialize state");
                goto err;
        }

        parse_options (argc, argv);

        ret = gluster_getfs (&fs, state->gluster_url);
        if (ret == -1) {
                error (0, errno, state->url);
                goto err;
        }

        ret = apply_xlator_options (fs, &state->xlator_options);
        if (ret == -1) {
                error (0, errno, "failed to apply translator options");
                goto err;
        }

        if (state->debug) {
                ret = glfs_set_logging (fs, "/dev/stderr", GF_LOG_DEBUG);

                if (ret == -1) {
                        error (0, errno, "failed to set logging level");
                        goto err;
                }
        }

        ret = gluster_put (fs, state);
        if (ret == -1) {
                error (0, errno, state->url);
                goto err;
        }

        ret = EXIT_SUCCESS;
        goto out;

err:
        ret = EXIT_FAILURE;
out:
        if (fs) {
                glfs_fini (fs);
        }

        if (state) {
                gluster_url_free (state->gluster_url);
                free (state->url);
        }

        free (state);

        return ret;
}