Пример #1
0
/**
 * @brief Read from a data-server handle.
 *
 * NFSv4.1 data server handles are disjount from normal
 * filehandles (in Ganesha, there is a ds_flag in the filehandle_v4_t
 * structure) and do not get loaded into cache_inode or processed the
 * normal way.
 *
 * @param[in]  ds_pub           FSAL DS handle
 * @param[in]  req_ctx          Credentials
 * @param[in]  stateid          The stateid supplied with the READ operation,
 *                              for validation
 * @param[in]  offset           The offset at which to read
 * @param[in]  requested_length Length of read requested (and size of buffer)
 * @param[out] buffer           The buffer to which to store read data
 * @param[out] supplied_length  Length of data read
 * @param[out] eof              True on end of file
 *
 * @return An NFSv4.1 status code.
 */
static nfsstat4 ds_read(struct fsal_ds_handle *const ds_pub,
			struct req_op_context *const req_ctx,
			const stateid4 *stateid, const offset4 offset,
			const count4 requested_length, void *const buffer,
			count4 * const supplied_length,
			bool * const end_of_file)
{
	/* The private DS handle */
	struct glfs_ds_handle *ds =
		container_of(ds_pub, struct glfs_ds_handle, ds);
	int    rc = 0;
	struct glusterfs_export *glfs_export =
	container_of(ds_pub->pds->mds_fsal_export,
		     struct glusterfs_export, export);

	if (ds->glhandle == NULL)
		LogDebug(COMPONENT_PNFS, "ds_read glhandle NULL");

	rc = glfs_h_anonymous_read(glfs_export->gl_fs->fs, ds->glhandle,
				   buffer, requested_length, offset);
	if (rc < 0) {
		LogMajor(COMPONENT_PNFS, "Read failed on DS");
		return posix2nfs4_error(-rc);
	}

	*supplied_length = rc;
	if (rc == 0 || rc < requested_length)
		*end_of_file = true;


	return NFS4_OK;
}
Пример #2
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);
}