Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cbd4d4a8 authored by Bobi Jam's avatar Bobi Jam Committed by Greg Kroah-Hartman
Browse files

staging: lustre: llite: remove duplicate fiemap defines



 * replace struct ll_user_fiemap with struct fiemap
 * replace struct ll_fiemap_extent with struct fiemap_extent
 * remove kernel defined FIEMAP_EXTENT_* constants
 * remove kernel defined FIEMAP_FLAG_* flags
 * add member prefix for struct ll_fiemap_info_key

 * Add cl_object_operations::coo_fiemap().
 * Add cl_object_fiemap() to get FIEMAP mappings.

Signed-off-by: default avatarBobi Jam <bobijam.xu@intel.com>
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5823
Reviewed-on: http://review.whamcloud.com/12535
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-6201
Reviewed-on: http://review.whamcloud.com/13608


Reviewed-by: default avatarJohn L. Hammond <john.hammond@intel.com>
Reviewed-by: default avatarJinshan Xiong <jinshan.xiong@intel.com>
Reviewed-by: default avatarYang Sheng <yang.sheng@intel.com>
Reviewed-by: default avatarOleg Drokin <oleg.drokin@intel.com>
Signed-off-by: default avatarJames Simmons <jsimmons@infradead.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent e7226dd4
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -400,6 +400,12 @@ struct cl_object_operations {
	 */
	int (*coo_getstripe)(const struct lu_env *env, struct cl_object *obj,
			     struct lov_user_md __user *lum);
	/**
	 * Get FIEMAP mapping from the object.
	 */
	int (*coo_fiemap)(const struct lu_env *env, struct cl_object *obj,
			  struct ll_fiemap_info_key *fmkey,
			  struct fiemap *fiemap, size_t *buflen);
};

/**
@@ -2184,6 +2190,9 @@ int cl_object_prune(const struct lu_env *env, struct cl_object *obj);
void cl_object_kill(const struct lu_env *env, struct cl_object *obj);
int  cl_object_getstripe(const struct lu_env *env, struct cl_object *obj,
			 struct lov_user_md __user *lum);
int cl_object_fiemap(const struct lu_env *env, struct cl_object *obj,
		     struct ll_fiemap_info_key *fmkey, struct fiemap *fiemap,
		     size_t *buflen);

/**
 * Returns true, iff \a o0 and \a o1 are slices of the same object.
+10 −65
Original line number Diff line number Diff line
@@ -41,79 +41,24 @@
#ifndef _LUSTRE_FIEMAP_H
#define _LUSTRE_FIEMAP_H

struct ll_fiemap_extent {
	__u64 fe_logical;  /* logical offset in bytes for the start of
			    * the extent from the beginning of the file
			    */
	__u64 fe_physical; /* physical offset in bytes for the start
			    * of the extent from the beginning of the disk
			    */
	__u64 fe_length;   /* length in bytes for this extent */
	__u64 fe_reserved64[2];
	__u32 fe_flags;    /* FIEMAP_EXTENT_* flags for this extent */
	__u32 fe_device;   /* device number for this extent */
	__u32 fe_reserved[2];
};

struct ll_user_fiemap {
	__u64 fm_start;  /* logical offset (inclusive) at
			  * which to start mapping (in)
			  */
	__u64 fm_length; /* logical length of mapping which
			  * userspace wants (in)
			  */
	__u32 fm_flags;  /* FIEMAP_FLAG_* flags for request (in/out) */
	__u32 fm_mapped_extents;/* number of extents that were mapped (out) */
	__u32 fm_extent_count;  /* size of fm_extents array (in) */
	__u32 fm_reserved;
	struct ll_fiemap_extent fm_extents[0]; /* array of mapped extents (out) */
};

#define FIEMAP_MAX_OFFSET      (~0ULL)
#ifndef __KERNEL__
#include <stddef.h>
#include <fiemap.h>
#endif

#define FIEMAP_FLAG_SYNC		0x00000001 /* sync file data before
						    * map
						    */
#define FIEMAP_FLAG_XATTR		0x00000002 /* map extended attribute
						    * tree
						    */
#define FIEMAP_EXTENT_LAST		0x00000001 /* Last extent in file. */
#define FIEMAP_EXTENT_UNKNOWN		0x00000002 /* Data location unknown. */
#define FIEMAP_EXTENT_DELALLOC		0x00000004 /* Location still pending.
						    * Sets EXTENT_UNKNOWN.
						    */
#define FIEMAP_EXTENT_ENCODED		0x00000008 /* Data can not be read
						    * while fs is unmounted
						    */
#define FIEMAP_EXTENT_DATA_ENCRYPTED	0x00000080 /* Data is encrypted by fs.
						    * Sets EXTENT_NO_DIRECT.
						    */
#define FIEMAP_EXTENT_NOT_ALIGNED       0x00000100 /* Extent offsets may not be
						    * block aligned.
						    */
#define FIEMAP_EXTENT_DATA_INLINE       0x00000200 /* Data mixed with metadata.
						    * Sets EXTENT_NOT_ALIGNED.*/
#define FIEMAP_EXTENT_DATA_TAIL		0x00000400 /* Multiple files in block.
						    * Sets EXTENT_NOT_ALIGNED.
						    */
#define FIEMAP_EXTENT_UNWRITTEN		0x00000800 /* Space allocated, but
						    * no data (i.e. zero).
						    */
#define FIEMAP_EXTENT_MERGED		0x00001000 /* File does not natively
						    * support extents. Result
						    * merged for efficiency.
						    */
/* XXX: We use fiemap_extent::fe_reserved[0] */
#define fe_device	fe_reserved[0]

static inline size_t fiemap_count_to_size(size_t extent_count)
{
	return (sizeof(struct ll_user_fiemap) + extent_count *
					       sizeof(struct ll_fiemap_extent));
	return sizeof(struct fiemap) + extent_count *
				       sizeof(struct fiemap_extent);
}

static inline unsigned fiemap_size_to_count(size_t array_size)
{
	return ((array_size - sizeof(struct ll_user_fiemap)) /
					       sizeof(struct ll_fiemap_extent));
	return (array_size - sizeof(struct fiemap)) /
		sizeof(struct fiemap_extent);
}

#define FIEMAP_FLAG_DEVICE_ORDER 0x40000000 /* return device ordered mapping */
+4 −4
Original line number Diff line number Diff line
@@ -3331,14 +3331,14 @@ struct ost_body {

/* Key for FIEMAP to be used in get_info calls */
struct ll_fiemap_info_key {
	char    name[8];
	struct  obdo oa;
	struct  ll_user_fiemap fiemap;
	char		lfik_name[8];
	struct obdo	lfik_oa;
	struct fiemap	lfik_fiemap;
};

void lustre_swab_ost_body(struct ost_body *b);
void lustre_swab_ost_last_id(__u64 *id);
void lustre_swab_fiemap(struct ll_user_fiemap *fiemap);
void lustre_swab_fiemap(struct fiemap *fiemap);

void lustre_swab_lov_user_md_v1(struct lov_user_md_v1 *lum);
void lustre_swab_lov_user_md_v3(struct lov_user_md_v3 *lum);
+0 −1
Original line number Diff line number Diff line
@@ -82,7 +82,6 @@ typedef struct stat lstat_t;
#define FSFILT_IOC_SETVERSION	     _IOW('f', 4, long)
#define FSFILT_IOC_GETVERSION_OLD	 _IOR('v', 1, long)
#define FSFILT_IOC_SETVERSION_OLD	 _IOW('v', 2, long)
#define FSFILT_IOC_FIEMAP		 _IOWR('f', 11, struct ll_user_fiemap)
#endif

/* FIEMAP flags supported by Lustre */
+25 −101
Original line number Diff line number Diff line
@@ -1506,15 +1506,17 @@ int ll_release_openhandle(struct inode *inode, struct lookup_intent *it)
/**
 * Get size for inode for which FIEMAP mapping is requested.
 * Make the FIEMAP get_info call and returns the result.
 *
 * \param fiemap	kernel buffer to hold extens
 * \param num_bytes	kernel buffer size
 */
static int ll_do_fiemap(struct inode *inode, struct ll_user_fiemap *fiemap,
static int ll_do_fiemap(struct inode *inode, struct fiemap *fiemap,
			size_t num_bytes)
{
	struct obd_export *exp = ll_i2dtexp(inode);
	struct lov_stripe_md *lsm = NULL;
	struct ll_fiemap_info_key fm_key = { .name = KEY_FIEMAP, };
	__u32 vallen = num_bytes;
	int rc;
	struct ll_fiemap_info_key fmkey = { .lfik_name = KEY_FIEMAP, };
	struct lu_env *env;
	int refcheck;
	int rc = 0;

	/* Checks for fiemap flags */
	if (fiemap->fm_flags & ~LUSTRE_FIEMAP_FLAGS_COMPAT) {
@@ -1529,21 +1531,9 @@ static int ll_do_fiemap(struct inode *inode, struct ll_user_fiemap *fiemap,
			return rc;
	}

	lsm = ccc_inode_lsm_get(inode);
	if (!lsm)
		return -ENOENT;

	/* If the stripe_count > 1 and the application does not understand
	 * DEVICE_ORDER flag, then it cannot interpret the extents correctly.
	 */
	if (lsm->lsm_stripe_count > 1 &&
	    !(fiemap->fm_flags & FIEMAP_FLAG_DEVICE_ORDER)) {
		rc = -EOPNOTSUPP;
		goto out;
	}

	fm_key.oa.o_oi = lsm->lsm_oi;
	fm_key.oa.o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
	env = cl_env_get(&refcheck);
	if (IS_ERR(env))
		return PTR_ERR(env);

	if (i_size_read(inode) == 0) {
		rc = ll_glimpse_size(inode);
@@ -1551,24 +1541,23 @@ static int ll_do_fiemap(struct inode *inode, struct ll_user_fiemap *fiemap,
			goto out;
	}

	obdo_from_inode(&fm_key.oa, inode, OBD_MD_FLSIZE);
	obdo_set_parent_fid(&fm_key.oa, &ll_i2info(inode)->lli_fid);
	fmkey.lfik_oa.o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
	obdo_from_inode(&fmkey.lfik_oa, inode, OBD_MD_FLSIZE);
	obdo_set_parent_fid(&fmkey.lfik_oa, &ll_i2info(inode)->lli_fid);

	/* If filesize is 0, then there would be no objects for mapping */
	if (fm_key.oa.o_size == 0) {
	if (fmkey.lfik_oa.o_size == 0) {
		fiemap->fm_mapped_extents = 0;
		rc = 0;
		goto out;
	}

	memcpy(&fm_key.fiemap, fiemap, sizeof(*fiemap));

	rc = obd_get_info(NULL, exp, sizeof(fm_key), &fm_key, &vallen,
			  fiemap, lsm);
	if (rc)
		CERROR("obd_get_info failed: rc = %d\n", rc);
	memcpy(&fmkey.lfik_fiemap, fiemap, sizeof(*fiemap));

	rc = cl_object_fiemap(env, ll_i2info(inode)->lli_clob,
			      &fmkey, fiemap, &num_bytes);
out:
	ccc_inode_lsm_put(inode, lsm);
	cl_env_put(env, &refcheck);
	return rc;
}

@@ -1616,68 +1605,6 @@ int ll_fid2path(struct inode *inode, void __user *arg)
	return rc;
}

static int ll_ioctl_fiemap(struct inode *inode, unsigned long arg)
{
	struct ll_user_fiemap *fiemap_s;
	size_t num_bytes, ret_bytes;
	unsigned int extent_count;
	int rc = 0;

	/* Get the extent count so we can calculate the size of
	 * required fiemap buffer
	 */
	if (get_user(extent_count,
		     &((struct ll_user_fiemap __user *)arg)->fm_extent_count))
		return -EFAULT;

	if (extent_count >=
	    (SIZE_MAX - sizeof(*fiemap_s)) / sizeof(struct ll_fiemap_extent))
		return -EINVAL;
	num_bytes = sizeof(*fiemap_s) + (extent_count *
					 sizeof(struct ll_fiemap_extent));

	fiemap_s = libcfs_kvzalloc(num_bytes, GFP_NOFS);
	if (!fiemap_s)
		return -ENOMEM;

	/* get the fiemap value */
	if (copy_from_user(fiemap_s, (struct ll_user_fiemap __user *)arg,
			   sizeof(*fiemap_s))) {
		rc = -EFAULT;
		goto error;
	}

	/* If fm_extent_count is non-zero, read the first extent since
	 * it is used to calculate end_offset and device from previous
	 * fiemap call.
	 */
	if (extent_count) {
		if (copy_from_user(&fiemap_s->fm_extents[0],
				   (char __user *)arg + sizeof(*fiemap_s),
				   sizeof(struct ll_fiemap_extent))) {
			rc = -EFAULT;
			goto error;
		}
	}

	rc = ll_do_fiemap(inode, fiemap_s, num_bytes);
	if (rc)
		goto error;

	ret_bytes = sizeof(struct ll_user_fiemap);

	if (extent_count != 0)
		ret_bytes += (fiemap_s->fm_mapped_extents *
				 sizeof(struct ll_fiemap_extent));

	if (copy_to_user((void __user *)arg, fiemap_s, ret_bytes))
		rc = -EFAULT;

error:
	kvfree(fiemap_s);
	return rc;
}

/*
 * Read the data_version for inode.
 *
@@ -2119,8 +2046,6 @@ ll_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
	case LL_IOC_LOV_GETSTRIPE:
		return ll_file_getstripe(inode,
					 (struct lov_user_md __user *)arg);
	case FSFILT_IOC_FIEMAP:
		return ll_ioctl_fiemap(inode, arg);
	case FSFILT_IOC_GETFLAGS:
	case FSFILT_IOC_SETFLAGS:
		return ll_iocontrol(inode, file, cmd, arg);
@@ -3022,13 +2947,12 @@ static int ll_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
{
	int rc;
	size_t num_bytes;
	struct ll_user_fiemap *fiemap;
	struct fiemap *fiemap;
	unsigned int extent_count = fieinfo->fi_extents_max;

	num_bytes = sizeof(*fiemap) + (extent_count *
				       sizeof(struct ll_fiemap_extent));
				       sizeof(struct fiemap_extent));
	fiemap = libcfs_kvzalloc(num_bytes, GFP_NOFS);

	if (!fiemap)
		return -ENOMEM;

@@ -3036,9 +2960,10 @@ static int ll_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
	fiemap->fm_extent_count = fieinfo->fi_extents_max;
	fiemap->fm_start = start;
	fiemap->fm_length = len;

	if (extent_count > 0 &&
	    copy_from_user(&fiemap->fm_extents[0], fieinfo->fi_extents_start,
			   sizeof(struct ll_fiemap_extent)) != 0) {
			   sizeof(struct fiemap_extent))) {
		rc = -EFAULT;
		goto out;
	}
@@ -3050,11 +2975,10 @@ static int ll_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
	if (extent_count > 0 &&
	    copy_to_user(fieinfo->fi_extents_start, &fiemap->fm_extents[0],
			 fiemap->fm_mapped_extents *
			 sizeof(struct ll_fiemap_extent)) != 0) {
			 sizeof(struct fiemap_extent))) {
		rc = -EFAULT;
		goto out;
	}

out:
	kvfree(fiemap);
	return rc;
Loading