int write_something (glfs_t *fs) { glfs_fd_t *fd = NULL; char *buf = NULL; int ret = 0; int j = 0; fd = glfs_creat (fs, "filename", O_RDWR, 0644); if (!fd) { fprintf (stderr, "%s: (%p) %s\n", "filename", fd, strerror (errno)); return -1; } buf = (char *) malloc (WRITE_SIZE); memset (buf, '-', WRITE_SIZE); for (j = 0; j < 4; j++) { ret = glfs_write (fd, buf, WRITE_SIZE, 0); if (ret < 0) { fprintf (stderr, "Write(%s): %d (%s)\n", "filename", ret, strerror (errno)); return ret; } glfs_lseek (fd, 0, SEEK_SET); } return 0; }
boffset_t gfapi_device::d_lseek(DCR *dcr, boffset_t offset, int whence) { if (m_gfd) { return glfs_lseek(m_gfd, offset, whence); } else { errno = EBADF; return -1; } }
static int64_t qemu_gluster_getlength(BlockDriverState *bs) { BDRVGlusterState *s = bs->opaque; int64_t ret; ret = glfs_lseek(s->fd, 0, SEEK_END); if (ret < 0) { return -errno; } else { return ret; } }
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; }
static int fio_gf_prep(struct thread_data *td, struct io_u *io_u) { struct fio_file *f = io_u->file; struct gf_data *g = td->io_ops_data; dprint(FD_FILE, "fio prep\n"); if (!ddir_rw(io_u->ddir)) return 0; if (LAST_POS(f) != -1ULL && LAST_POS(f) == io_u->offset) return 0; if (glfs_lseek(g->fd, io_u->offset, SEEK_SET) < 0) { td_verror(td, errno, "lseek"); return 1; } return 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 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); }
long glfs_java_seek_end (glfs_fd_t *glfd, off_t location) { return glfs_lseek (glfd, location, SEEK_END); }
long glfs_java_seek_current (glfs_fd_t *glfd, off_t location) { return glfs_lseek (glfd, location, SEEK_CUR); }
long glfs_java_seek_set (glfs_fd_t *glfd, off_t location) { return glfs_lseek (glfd, location, SEEK_SET); }
static int large_read_write (glfs_t *fs) { int ret = 0; int j = 0; glfs_fd_t *fd = NULL; glfs_fd_t *fd1 = NULL; char *filename = NULL; char *buf = NULL; ret = asprintf (&filename, "filerw%d", extension); if (ret < 0) { fprintf (stderr, "cannot construct filename (%s)", strerror (errno)); return ret; } extension++; fd = glfs_creat (fs, filename, O_RDWR, 0644); if (!fd) { fprintf (stderr, "%s: (%p) %s\n", filename, fd, strerror (errno)); return -1; } buf = (char *) malloc (WRITE_SIZE); memset (buf, '-', WRITE_SIZE); for (j = 0; j < READ_WRITE_LOOP; j++) { ret = glfs_write (fd, buf, WRITE_SIZE, 0); if (ret < 0) { fprintf (stderr, "Write(%s): %d (%s)\n", filename, ret, strerror (errno)); return ret; } } fd1 = glfs_open (fs, filename, O_RDWR); if (fd1 < 0) { fprintf (stderr, "Open(%s): %d (%s)\n", filename, ret, strerror (errno)); return -1; } glfs_lseek (fd1, 0, SEEK_SET); for (j = 0; j < READ_WRITE_LOOP; j++) { ret = glfs_read (fd1, buf, WRITE_SIZE, 0); if (ret < 0) { fprintf (stderr, "Read(%s): %d (%s)\n", filename, ret, strerror (errno)); return ret; } } for (j = 0; j < READ_WRITE_LOOP; j++) { ret = glfs_write (fd1, buf, WRITE_SIZE, 0); if (ret < 0) { fprintf (stderr, "Write(%s): %d (%s)\n", filename, ret, strerror (errno)); return ret; } } glfs_close (fd); glfs_close (fd1); ret = glfs_unlink (fs, filename); if (ret < 0) { fprintf (stderr, "glfs_unlink failed with ret: %d (%s)\n", ret, strerror (errno)); return -1; } free (buf); free (filename); }
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); }
int gluster_put (glfs_t *fs, struct state *state) { int ret = -1; glfs_fd_t *fd = NULL; char *filename = state->gluster_url->path; char *dir_path = strdup (state->gluster_url->path); struct stat statbuf; if (dir_path == NULL) { error (EXIT_FAILURE, errno, "strdup"); goto out; } ret = glfs_lstat (fs, filename, &statbuf); if (ret != -1 && !state->append && !state->overwrite) { errno = EEXIST; ret = -1; goto out; } if (state->parents) { ret = gluster_create_path (fs, dir_path, get_default_dir_mode_perm ()); if (ret == -1) { goto out; } } fd = glfs_creat (fs, filename, O_RDWR, get_default_file_mode_perm ()); if (fd == NULL) { ret = -1; goto out; } ret = gluster_lock (fd, F_WRLCK); if (ret == -1) { goto out; } if (state->append) { ret = glfs_lseek (fd, 0, SEEK_END); if (ret == -1) { error (0, errno, "seek error: %s", filename); goto out; } } else { ret = glfs_ftruncate (fd, 0); if (ret == -1) { error (0, errno, "truncate error: %s", filename); goto out; } } if (gluster_write (STDIN_FILENO, fd) == 0) { ret = -1; } out: free (dir_path); if (fd) { glfs_close (fd); } return ret; }