예제 #1
0
/**
 * Get the index of an xattr based on its name
 *
 *   \param p_objecthandle Handle of the object you want to get attribute for.
 *   \param xattr_name the name of the attribute to be read.
 *   \param pxattr_id found xattr_id
 *   
 *   \return ERR_FSAL_NO_ERROR if xattr_name exists, ERR_FSAL_NOENT otherwise
 */
fsal_status_t ZFSFSAL_GetXAttrIdByName(fsal_handle_t * obj_handle,     /* IN */
                                    const fsal_name_t * xattr_name,     /* IN */
                                    fsal_op_context_t * context,      /* IN */
                                    unsigned int *pxattr_id     /* OUT */
    )
{
  unsigned int index;
  int rc;
  int found = FALSE;
  zfsfsal_handle_t *p_objecthandle = (zfsfsal_handle_t *)obj_handle;
  zfsfsal_op_context_t *p_context = (zfsfsal_op_context_t *)context;

  /* sanity checks */
  if(!p_objecthandle || !xattr_name)
    Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_GetXAttrValue);

  for(index = 0; index < XATTR_COUNT; index++)
    {
      if(!strcmp(xattr_list[index].xattr_name, xattr_name->name))
        {
          found = TRUE;
          break;
        }
    }

  if(!found)
  {

    /* Get the right VFS */
    ZFSFSAL_VFS_RDLock();
    libzfswrap_vfs_t *p_vfs = ZFSFSAL_GetVFS(p_objecthandle);
    if(!p_vfs)
    {
      ZFSFSAL_VFS_Unlock();
      Return(ERR_FSAL_NOENT, 0, INDEX_FSAL_access);
    }

    if((rc = xattr_name_to_id(p_vfs, p_context, p_objecthandle, xattr_name->name, &index)))
    {
      ZFSFSAL_VFS_Unlock();
      Return(rc, 0, INDEX_FSAL_GetXAttrValue);
    }
    found = TRUE;
  }

  if(found)
  {
    *pxattr_id = index;
    Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_GetXAttrValue);
  }
  else
    Return(ERR_FSAL_NOENT, ENOENT, INDEX_FSAL_GetXAttrValue);
}
예제 #2
0
파일: xattrs.c 프로젝트: asias/nfs-ganesha
fsal_status_t vfs_getextattr_id_by_name(struct fsal_obj_handle *obj_hdl,
					const struct req_op_context *opctx,
					const char *xattr_name,
					unsigned int *pxattr_id)
{
	unsigned int index;
	int rc;
	int found = FALSE;
	struct vfs_fsal_obj_handle *obj_handle = NULL;
	int fd = -1;

	obj_handle =
	    container_of(obj_hdl, struct vfs_fsal_obj_handle, obj_handle);
	for (index = 0; index < XATTR_COUNT; index++) {
		if (!strcmp(xattr_list[index].xattr_name, xattr_name)) {
			found = TRUE;
			break;
		}
	}

	/* search in xattrs */
	if (!found) {
		fsal_errors_t fe;
		fd = (obj_hdl->type == DIRECTORY) ?
			vfs_fsal_open(obj_handle, O_DIRECTORY, &fe) :
			vfs_fsal_open(obj_handle, O_RDWR, &fe);
		if (fd < 0)
			return fsalstat(fe, -fd);

		errno = 0;
		rc = xattr_name_to_id(fd, xattr_name);
		if (rc < 0) {
			close(fd);
			return fsalstat(-rc, errno);
		} else {
			index = rc;
		}
		close(fd);
	}

	/* If we're here, we got it (early return on error) */
	*pxattr_id = index;
	return fsalstat(ERR_FSAL_NO_ERROR, 0);
}
예제 #3
0
파일: xattrs.c 프로젝트: JevonQ/nfs-ganesha
fsal_status_t tank_getextattr_id_by_name(struct fsal_obj_handle *obj_hdl,
					 const char *xattr_name,
					 unsigned int *pxattr_id)
{
	unsigned int index;
	int rc;
	bool found = false;
	struct zfs_fsal_obj_handle *obj_handle = NULL;
	creden_t cred;

	/* sanity checks */
	if (!obj_hdl || !xattr_name)
		return fsalstat(ERR_FSAL_FAULT, 0);

	obj_handle =
	    container_of(obj_hdl, struct zfs_fsal_obj_handle, obj_handle);

	cred.uid = op_ctx->creds->caller_uid;
	cred.gid = op_ctx->creds->caller_gid;

	for (index = 0; index < XATTR_COUNT; index++) {
		if (!strcmp(xattr_list[index].xattr_name, xattr_name)) {
			found = true;
			break;
		}
	}

	/* search in xattrs */
	if (!found) {
		rc = xattr_name_to_id(ZFSFSAL_GetVFS(obj_handle->handle), &cred,
				      obj_handle->handle->zfs_handle,
				      (char *)xattr_name);
		if (rc)
			return fsalstat(posix2fsal_error(rc), rc);
		else {
			index = rc;
			found = true;
		}
	}
	*pxattr_id = index;
	return fsalstat(ERR_FSAL_NO_ERROR, 0);
}