Example #1
0
int
old_readdir(glfs_t *fs)
{
    struct glfs_object *root = NULL;
    struct glfs_fd *fd = NULL;
    struct stat *sb = NULL;
    char buf[512];
    struct dirent *entry = NULL;
    int ret = -1;
    struct glfs_object *glhandle = NULL;

    if (!fs)
        return -1;

    root = glfs_h_lookupat(fs, NULL, "/", sb, 0);
    VALIDATE_BOOL_AND_GOTO_LABEL_ON_ERROR("glfs_h_lookupat", !!root, ret, out);

    fd = glfs_opendir(fs, "/");
    VALIDATE_BOOL_AND_GOTO_LABEL_ON_ERROR("glfs_opendir", !!fd, ret, out);

    while (glfs_readdir_r(fd, (struct dirent *)buf, &entry), entry) {
        if (strcmp(entry->d_name, ".") && strcmp(entry->d_name, "..")) {
            glhandle = glfs_h_lookupat(fs, root, "/", sb, 0);
            VALIDATE_BOOL_AND_GOTO_LABEL_ON_ERROR("glfs_h_lookupat", !!glhandle,
                                                  ret, out);
        }
    }

    glfs_closedir(fd);

    ret = 0;
out:
    return ret;
}
Example #2
0
static fsal_status_t lookup(struct fsal_obj_handle *parent,
			    const struct req_op_context *opctx,
			    const char *path, struct fsal_obj_handle **handle)
{
	int rc = 0;
	fsal_status_t status = { ERR_FSAL_NO_ERROR, 0 };
	struct stat sb;
	struct glfs_object *glhandle = NULL;
	unsigned char globjhdl[GLAPI_HANDLE_LENGTH];
	struct glusterfs_handle *objhandle = NULL;
	struct glusterfs_export *glfs_export =
	    container_of(parent->export, struct glusterfs_export, export);
	struct glusterfs_handle *parenthandle =
	    container_of(parent, struct glusterfs_handle, handle);
#ifdef GLTIMING
	struct timespec s_time, e_time;

	now(&s_time);
#endif

	glhandle =
	    glfs_h_lookupat(glfs_export->gl_fs, parenthandle->glhandle, path,
			    &sb);
	if (glhandle == NULL) {
		status = gluster2fsal_error(errno);
		goto out;
	}

	rc = glfs_h_extract_handle(glhandle, globjhdl, GLAPI_HANDLE_LENGTH);
	if (rc < 0) {
		status = gluster2fsal_error(errno);
		goto out;
	}

	rc = construct_handle(glfs_export, &sb, glhandle, globjhdl,
			      GLAPI_HANDLE_LENGTH, &objhandle);
	if (rc != 0) {
		status = gluster2fsal_error(rc);
		goto out;
	}

	*handle = &objhandle->handle;

 out:
	if (status.major != ERR_FSAL_NO_ERROR) {
		gluster_cleanup_vars(glhandle);
	}
#ifdef GLTIMING
	now(&e_time);
	latency_update(&s_time, &e_time, lat_lookup);
#endif

	return status;
}
Example #3
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 #4
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 #5
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 #6
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);
}
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);
}