コード例 #1
0
ファイル: gfapi_device.c プロジェクト: NilByMouth/bareos
bool gfapi_device::d_truncate(DCR *dcr)
{
   struct stat st;

   if (m_gfd) {
      if (glfs_ftruncate(m_gfd, 0) != 0) {
         berrno be;

         Mmsg2(errmsg, _("Unable to truncate device %s. ERR=%s\n"),
               print_name(), be.bstrerror());
         Emsg0(M_FATAL, 0, errmsg);
         return false;
      }

      /*
       * Check for a successful glfs_truncate() and issue work-around when truncation doesn't work.
       *
       * 1. close file
       * 2. delete file
       * 3. open new file with same mode
       * 4. change ownership to original
       */
      if (glfs_fstat(m_gfd, &st) != 0) {
         berrno be;

         Mmsg2(errmsg, _("Unable to stat device %s. ERR=%s\n"), print_name(), be.bstrerror());
         return false;
      }

      if (st.st_size != 0) {             /* glfs_truncate() didn't work */
         glfs_close(m_gfd);
         glfs_unlink(m_glfs, getVolCatName());

         set_mode(CREATE_READ_WRITE);

         /*
          * Recreate the file -- of course, empty
          */
         m_gfd = glfs_creat(m_glfs, getVolCatName(), oflags, st.st_mode);
         if (!m_gfd) {
            berrno be;

            dev_errno = errno;
            Mmsg2(errmsg, _("Could not reopen: %s, ERR=%s\n"), getVolCatName(), be.bstrerror());
            Emsg0(M_FATAL, 0, errmsg);

            return false;
         }

         /*
          * Reset proper owner
          */
         glfs_chown(m_glfs, getVolCatName(), st.st_uid, st.st_gid);
      }
   }

   return true;
}
コード例 #2
0
ファイル: gluster.c プロジェクト: NormanM/qemu
static int64_t qemu_gluster_allocated_file_size(BlockDriverState *bs)
{
    BDRVGlusterState *s = bs->opaque;
    struct stat st;
    int ret;

    ret = glfs_fstat(s->fd, &st);
    if (ret < 0) {
        return -errno;
    } else {
        return st.st_blocks * 512;
    }
}
コード例 #3
0
ファイル: xglfs_fgetattr.c プロジェクト: gluster/xglfs
int xglfs_fgetattr(const char* _path, struct stat* _statbuf, struct fuse_file_info* _info)
{
	int ret = 0;

	if (!strcmp(_path, "/"))
		ret = xglfs_getattr(_path, _statbuf);
	else
	{
		ret = glfs_fstat(FH_TO_FD(_info->fh), _statbuf);
		if (unlikely(ret < 0))
			ret = -errno;
	}

	return ret;
}
コード例 #4
0
ファイル: handle.c プロジェクト: asias/nfs-ganesha
static fsal_status_t getattrs(struct fsal_obj_handle *obj_hdl,
			      const struct req_op_context *opctx)
{
	int rc = 0;
	fsal_status_t status = { ERR_FSAL_NO_ERROR, 0 };
	struct stat sb;
	struct glusterfs_export *glfs_export =
	    container_of(obj_hdl->export, struct glusterfs_export, export);
	struct glusterfs_handle *objhandle =
	    container_of(obj_hdl, struct glusterfs_handle, handle);
#ifdef GLTIMING
	struct timespec s_time, e_time;

	now(&s_time);
#endif

	/* FIXME: Should we hold the fd so that any async op does
	 * not close it */
	if (objhandle->openflags != FSAL_O_CLOSED) {
		rc = glfs_fstat(objhandle->glfd, &sb);
	} else {
		rc = glfs_h_stat(glfs_export->gl_fs, objhandle->glhandle, &sb);
	}

	if (rc != 0) {
		if (errno == ENOENT)
			status = gluster2fsal_error(ESTALE);
		else
			status = gluster2fsal_error(errno);

		goto out;
	}

	stat2fsal_attributes(&sb, &objhandle->handle.attributes);

 out:
#ifdef GLTIMING
	now(&e_time);
	latency_update(&s_time, &e_time, lat_getattrs);
#endif

	return status;
}
コード例 #5
0
ファイル: glusterfs.c プロジェクト: huzichunjohn/uwsgi
static int uwsgi_glusterfs_request(struct wsgi_request *wsgi_req) {
	char filename[PATH_MAX+1];
	/* Standard GlusterFS request */
        if (!wsgi_req->uh->pktsize) {
                uwsgi_log( "Empty GlusterFS request. skip.\n");
                return -1;
        }

        if (uwsgi_parse_vars(wsgi_req)) {
                return -1;
        }

	// blocks empty paths
	if (wsgi_req->path_info_len == 0 || wsgi_req->path_info_len > PATH_MAX) {
                uwsgi_403(wsgi_req);
                return UWSGI_OK;
	}

        wsgi_req->app_id = uwsgi_get_app_id(wsgi_req, wsgi_req->appid, wsgi_req->appid_len, glusterfs_plugin.modifier1);
	if (wsgi_req->app_id == -1 && !uwsgi.no_default_app && uwsgi.default_app > -1) {
        	if (uwsgi_apps[uwsgi.default_app].modifier1 == glusterfs_plugin.modifier1) {
                	wsgi_req->app_id = uwsgi.default_app;
                }
        }
        if (wsgi_req->app_id == -1) {
                uwsgi_404(wsgi_req);
                return UWSGI_OK;
        }

        struct uwsgi_app *ua = &uwsgi_apps[wsgi_req->app_id];

	memcpy(filename, wsgi_req->path_info, wsgi_req->path_info_len);
	filename[wsgi_req->path_info_len] = 0;

	glfs_fd_t *fd = glfs_open((glfs_t *) ua->interpreter, filename, O_RDONLY);
	if (!fd) {
                uwsgi_404(wsgi_req);
                return UWSGI_OK;
	}
	

	struct stat st;
	if (glfs_fstat(fd, &st)) {
		uwsgi_403(wsgi_req);
                return UWSGI_OK;
	}	

	if (uwsgi_response_prepare_headers(wsgi_req, "200 OK", 6)) goto end;
	size_t mime_type_len = 0;
        char *mime_type = uwsgi_get_mime_type(wsgi_req->path_info, wsgi_req->path_info_len, &mime_type_len);
        if (mime_type) {
        	if (uwsgi_response_add_content_type(wsgi_req, mime_type, mime_type_len)) goto end;
        }

        if (uwsgi_response_add_last_modified(wsgi_req, (uint64_t) st.st_mtime)) goto end;
	if (uwsgi_response_add_content_length(wsgi_req, st.st_size)) goto end;

	// skip body on HEAD
	if (uwsgi_strncmp(wsgi_req->method, wsgi_req->method_len, "HEAD", 4)) {
		size_t remains = st.st_size;
		while(remains > 0) {
			char buf[8192];
			ssize_t rlen = glfs_read (fd, buf, UMIN(remains, 8192), 0);
			if (rlen <= 0) goto end;
			if (uwsgi_response_write_body_do(wsgi_req, buf, rlen)) goto end;
			remains -= rlen;
		}
	}

end:
	glfs_close(fd);
	return UWSGI_OK;
}
コード例 #6
0
ファイル: gfapi-trunc.c プロジェクト: kshlm/glusterfs
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;
}