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; }
static nfsstat4 pnfs_layout_commit(struct fsal_obj_handle *obj_pub, struct req_op_context *req_ctx, XDR *lou_body, const struct fsal_layoutcommit_arg *arg, struct fsal_layoutcommit_res *res) { /* Old stat, so we don't truncate file or reverse time */ struct stat old_stat; /* new stat to set time and size */ struct stat new_stat; struct glusterfs_export *glfs_export = container_of(op_ctx->fsal_export, struct glusterfs_export, export); struct glusterfs_handle *objhandle = container_of(obj_pub, struct glusterfs_handle, handle); /* Mask to determine exactly what gets set */ int mask = 0; int rc = 0; if (arg->type != LAYOUT4_NFSV4_1_FILES) { LogMajor(COMPONENT_PNFS, "Unsupported layout type: %x", arg->type); return NFS4ERR_UNKNOWN_LAYOUTTYPE; } /* Gets previous status of file in the MDS */ rc = glfs_h_stat(glfs_export->gl_fs, objhandle->glhandle, &old_stat); if (rc != 0) { LogMajor(COMPONENT_PNFS, "Commit layout, stat unsucessfully completed"); return NFS4ERR_INVAL; } memset(&new_stat, 0, sizeof(struct stat)); /* Set the new attributes for the file if it is changed */ if (arg->new_offset) { if (old_stat.st_size < arg->last_write + 1) { new_stat.st_size = arg->last_write + 1; res->size_supplied = true; res->new_size = arg->last_write + 1; rc = glfs_h_truncate(glfs_export->gl_fs, objhandle->glhandle, res->new_size); if (rc != 0) { LogMajor(COMPONENT_PNFS, "Commit layout, size changed unsucessfully completed"); return NFS4ERR_INVAL; } } } if ((arg->time_changed) && (arg->new_time.seconds > old_stat.st_mtime)) new_stat.st_mtime = arg->new_time.seconds; else new_stat.st_mtime = time(NULL); mask |= GLAPI_SET_ATTR_MTIME; rc = glfs_h_setattrs(glfs_export->gl_fs, objhandle->glhandle, &new_stat, mask); if (rc != 0) { LogMajor(COMPONENT_PNFS, "commit layout, setattr unsucessflly completed"); return NFS4ERR_INVAL; } res->commit_done = true; return NFS4_OK; }