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

Commit 73bb1da6 authored by Peng Tao's avatar Peng Tao Committed by Greg Kroah-Hartman
Browse files

staging/lustre: adapt proc_dir_entry change

In 3.10 merge window, proc_dir_entry is now private to proc. However,
Lustre lprocfs depends heavily on it and its now-gone read_proc_t and
write_proc_t members.

The patch largely changed the fact, and made lprocfs depend on none of
proc_dir_entry private members. All lprocfs callers are converted to
use the new seq_file scheme.

Also lprocfs_srch is removed so that we can drop lprocfs_lock. All callers
are changed to save created pde in proper place.

See https://jira.hpdd.intel.com/browse/LU-3319

 for more details.

Signed-off-by: default avatarPeng Tao <tao.peng@emc.com>
Signed-off-by: default avatarAndreas Dilger <andreas.dilger@intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 2ac428fe
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -792,8 +792,9 @@ static inline void __cfs_hash_set_theta(cfs_hash_t *hs, int min, int max)
}

/* Generic debug formatting routines mainly for proc handler */
int cfs_hash_debug_header(char *str, int size);
int cfs_hash_debug_str(cfs_hash_t *hs, char *str, int size);
struct seq_file;
int cfs_hash_debug_header(struct seq_file *m);
int cfs_hash_debug_str(cfs_hash_t *hs, struct seq_file *m);

/*
 * Generic djb2 hash algorithm for character arrays.
+0 −64
Original line number Diff line number Diff line
@@ -58,7 +58,6 @@ typedef module_t *cfs_param_module_t;
typedef struct proc_dir_entry		   cfs_param_dentry_t;
typedef struct poll_table_struct		cfs_poll_table_t;
#define CFS_PARAM_MODULE			THIS_MODULE
#define CFS_PDE(value)			  PDE(value)
#define cfs_file_private(file)		  (file->private_data)
#define cfs_dentry_data(dentry)		 (dentry->data)
#define cfs_proc_inode_pde(proc_inode)	  (proc_inode->pde)
@@ -75,52 +74,6 @@ typedef struct poll_table_struct cfs_poll_table_t;
							    count, ppos))
#define cfs_seq_open(file, ops, rc)	     (rc = seq_open(file, ops))

/* in lprocfs_stat.c, to protect the private data for proc entries */
extern struct rw_semaphore		_lprocfs_lock;

/* to begin from 2.6.23, Linux defines self file_operations (proc_reg_file_ops)
 * in procfs, the proc file_operation defined by Lustre (lprocfs_generic_fops)
 * will be wrapped into the new defined proc_reg_file_ops, which instroduces
 * user count in proc_dir_entrey(pde_users) to protect the proc entry from
 * being deleted. then the protection lock (_lprocfs_lock) defined by Lustre
 * isn't necessary anymore for lprocfs_generic_fops(e.g. lprocfs_fops_read).
 * see bug19706 for detailed information.
 */
#define LPROCFS_ENTRY() do{ }while(0)
#define LPROCFS_EXIT()  do{ }while(0)

static inline
int LPROCFS_ENTRY_AND_CHECK(struct proc_dir_entry *dp)
{
	int deleted = 0;

	spin_lock(&(dp)->pde_unload_lock);
	if (dp->proc_fops == NULL)
		deleted = 1;
	spin_unlock(&(dp)->pde_unload_lock);
	if (deleted)
		return -ENODEV;
	return 0;
}
#define LPROCFS_SRCH_ENTRY()	    \
do {				    \
	down_read(&_lprocfs_lock);      \
} while(0)

#define LPROCFS_SRCH_EXIT()	     \
do {				    \
	up_read(&_lprocfs_lock);	\
} while(0)

#define LPROCFS_WRITE_ENTRY()		\
do {					\
	down_write(&_lprocfs_lock);	\
} while(0)

#define LPROCFS_WRITE_EXIT()		\
do {					\
	up_write(&_lprocfs_lock);	\
} while(0)
#else /* !LPROCFS */

typedef struct cfs_params_file {
@@ -181,13 +134,7 @@ static inline cfs_proc_inode_t *FAKE_PROC_I(const cfs_inode_t *inode)
	return container_of(inode, cfs_proc_inode_t, param_inode);
}

static inline cfs_param_dentry_t *FAKE_PDE(cfs_inode_t *inode)
{
	return FAKE_PROC_I(inode)->param_pde;
}

#define CFS_PARAM_MODULE			NULL
#define CFS_PDE(value)			  FAKE_PDE(value)
#define cfs_file_private(file)		  (file->param_private)
#define cfs_dentry_data(dentry)		 (dentry->param_data)
#define cfs_proc_inode(proc_inode)	      (proc_inode->param_inode)
@@ -212,17 +159,6 @@ do { \
	rc = 0;					 \
} while(0)

#define LPROCFS_ENTRY()	     do {} while(0)
#define LPROCFS_EXIT()	      do {} while(0)
static inline
int LPROCFS_ENTRY_AND_CHECK(cfs_param_dentry_t *dp)
{
	LPROCFS_ENTRY();
	return 0;
}
#define LPROCFS_WRITE_ENTRY()       do {} while(0)
#define LPROCFS_WRITE_EXIT()	do {} while(0)

#endif /* LPROCFS */

/* XXX: params_tree APIs */
+0 −2
Original line number Diff line number Diff line
@@ -57,10 +57,8 @@ enum {

extern struct lu_context_key seq_thread_key;

/* Functions used internally in module. */
int seq_client_alloc_super(struct lu_client_seq *seq,
			   const struct lu_env *env);

/* Store API functions. */
int seq_store_init(struct lu_server_seq *seq,
		   const struct lu_env *env,
+38 −176
Original line number Diff line number Diff line
@@ -60,8 +60,7 @@
 * use.
 */
static int
seq_proc_write_common(struct file *file, const char *buffer,
		      unsigned long count, void *data,
lprocfs_fid_write_common(const char *buffer, unsigned long count,
			 struct lu_seq_range *range)
{
	struct lu_seq_range tmp;
@@ -79,151 +78,19 @@ seq_proc_write_common(struct file *file, const char *buffer,
	RETURN(0);
}

static int
seq_proc_read_common(char *page, char **start, off_t off,
		     int count, int *eof, void *data,
		     struct lu_seq_range *range)
{
	int rc;
	ENTRY;

	*eof = 1;
	rc = snprintf(page, count, "["LPX64" - "LPX64"]:%x:%s\n",
			PRANGE(range));
	RETURN(rc);
}

/*
 * Server side procfs stuff.
 */
static int
seq_server_proc_write_space(struct file *file, const char *buffer,
			    unsigned long count, void *data)
{
	struct lu_server_seq *seq = (struct lu_server_seq *)data;
	int rc;
	ENTRY;

	LASSERT(seq != NULL);

	mutex_lock(&seq->lss_mutex);
	rc = seq_proc_write_common(file, buffer, count,
				   data, &seq->lss_space);
	if (rc == 0) {
		CDEBUG(D_INFO, "%s: Space: "DRANGE"\n",
		       seq->lss_name, PRANGE(&seq->lss_space));
	}

	mutex_unlock(&seq->lss_mutex);

	RETURN(count);
}

static int
seq_server_proc_read_space(char *page, char **start, off_t off,
			   int count, int *eof, void *data)
{
	struct lu_server_seq *seq = (struct lu_server_seq *)data;
	int rc;
	ENTRY;

	LASSERT(seq != NULL);

	mutex_lock(&seq->lss_mutex);
	rc = seq_proc_read_common(page, start, off, count, eof,
				  data, &seq->lss_space);
	mutex_unlock(&seq->lss_mutex);

	RETURN(rc);
}

static int
seq_server_proc_read_server(char *page, char **start, off_t off,
			    int count, int *eof, void *data)
{
	struct lu_server_seq *seq = (struct lu_server_seq *)data;
	struct client_obd *cli;
	int rc;
	ENTRY;

	LASSERT(seq != NULL);

	*eof = 1;
	if (seq->lss_cli) {
		if (seq->lss_cli->lcs_exp != NULL) {
			cli = &seq->lss_cli->lcs_exp->exp_obd->u.cli;
			rc = snprintf(page, count, "%s\n",
				      cli->cl_target_uuid.uuid);
		} else {
			rc = snprintf(page, count, "%s\n",
				      seq->lss_cli->lcs_srv->lss_name);
		}
	} else {
		rc = snprintf(page, count, "<none>\n");
	}

	RETURN(rc);
}

static int
seq_server_proc_write_width(struct file *file, const char *buffer,
			    unsigned long count, void *data)
{
	struct lu_server_seq *seq = (struct lu_server_seq *)data;
	int rc, val;
	ENTRY;

	LASSERT(seq != NULL);

	mutex_lock(&seq->lss_mutex);

	rc = lprocfs_write_helper(buffer, count, &val);
	if (rc != 0) {
		CERROR("%s: invalid width.\n", seq->lss_name);
		GOTO(out_unlock, rc);
	}

	seq->lss_width = val;

	CDEBUG(D_INFO, "%s: Width: "LPU64"\n",
	       seq->lss_name, seq->lss_width);
out_unlock:
	mutex_unlock(&seq->lss_mutex);

	RETURN(count);
}

static int
seq_server_proc_read_width(char *page, char **start, off_t off,
			   int count, int *eof, void *data)
{
	struct lu_server_seq *seq = (struct lu_server_seq *)data;
	int rc;
	ENTRY;

	LASSERT(seq != NULL);

	mutex_lock(&seq->lss_mutex);
	rc = snprintf(page, count, LPU64"\n", seq->lss_width);
	mutex_unlock(&seq->lss_mutex);

	RETURN(rc);
}

/* Client side procfs stuff */
static int
seq_client_proc_write_space(struct file *file, const char *buffer,
			    unsigned long count, void *data)
static ssize_t
lprocfs_fid_space_seq_write(struct file *file, const char *buffer,
			    size_t count, loff_t *off)
{
	struct lu_client_seq *seq = (struct lu_client_seq *)data;
	struct lu_client_seq *seq = ((struct seq_file *)file->private_data)->private;
	int rc;
	ENTRY;

	LASSERT(seq != NULL);

	mutex_lock(&seq->lcs_mutex);
	rc = seq_proc_write_common(file, buffer, count,
				   data, &seq->lcs_space);
	rc = lprocfs_fid_write_common(buffer, count, &seq->lcs_space);

	if (rc == 0) {
		CDEBUG(D_INFO, "%s: Space: "DRANGE"\n",
@@ -236,42 +103,37 @@ seq_client_proc_write_space(struct file *file, const char *buffer,
}

static int
seq_client_proc_read_space(char *page, char **start, off_t off,
			   int count, int *eof, void *data)
lprocfs_fid_space_seq_show(struct seq_file *m, void *unused)
{
	struct lu_client_seq *seq = (struct lu_client_seq *)data;
	struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
	int rc;
	ENTRY;

	LASSERT(seq != NULL);

	mutex_lock(&seq->lcs_mutex);
	rc = seq_proc_read_common(page, start, off, count, eof,
				  data, &seq->lcs_space);
	rc = seq_printf(m, "["LPX64" - "LPX64"]:%x:%s\n", PRANGE(&seq->lcs_space));
	mutex_unlock(&seq->lcs_mutex);

	RETURN(rc);
}

static int
seq_client_proc_write_width(struct file *file, const char *buffer,
			    unsigned long count, void *data)
static ssize_t
lprocfs_fid_width_seq_write(struct file *file, const char *buffer,
			    size_t count, loff_t *off)
{
	struct lu_client_seq *seq = (struct lu_client_seq *)data;
	struct lu_client_seq *seq = ((struct seq_file *)file->private_data)->private;
	__u64  max;
	int rc, val;
	ENTRY;

	LASSERT(seq != NULL);

	mutex_lock(&seq->lcs_mutex);

	rc = lprocfs_write_helper(buffer, count, &val);
	if (rc) {
		mutex_unlock(&seq->lcs_mutex);
	if (rc)
		RETURN(rc);
	}

	mutex_lock(&seq->lcs_mutex);
	if (seq->lcs_type == LUSTRE_SEQ_DATA)
		max = LUSTRE_DATA_SEQ_MAX_WIDTH;
	else
@@ -292,44 +154,41 @@ seq_client_proc_write_width(struct file *file, const char *buffer,
}

static int
seq_client_proc_read_width(char *page, char **start, off_t off,
			   int count, int *eof, void *data)
lprocfs_fid_width_seq_show(struct seq_file *m, void *unused)
{
	struct lu_client_seq *seq = (struct lu_client_seq *)data;
	struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
	int rc;
	ENTRY;

	LASSERT(seq != NULL);

	mutex_lock(&seq->lcs_mutex);
	rc = snprintf(page, count, LPU64"\n", seq->lcs_width);
	rc = seq_printf(m, LPU64"\n", seq->lcs_width);
	mutex_unlock(&seq->lcs_mutex);

	RETURN(rc);
}

static int
seq_client_proc_read_fid(char *page, char **start, off_t off,
			 int count, int *eof, void *data)
lprocfs_fid_fid_seq_show(struct seq_file *m, void *unused)
{
	struct lu_client_seq *seq = (struct lu_client_seq *)data;
	struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
	int rc;
	ENTRY;

	LASSERT(seq != NULL);

	mutex_lock(&seq->lcs_mutex);
	rc = snprintf(page, count, DFID"\n", PFID(&seq->lcs_fid));
	rc = seq_printf(m, DFID"\n", PFID(&seq->lcs_fid));
	mutex_unlock(&seq->lcs_mutex);

	RETURN(rc);
}

static int
seq_client_proc_read_server(char *page, char **start, off_t off,
			    int count, int *eof, void *data)
lprocfs_fid_server_seq_show(struct seq_file *m, void *unused)
{
	struct lu_client_seq *seq = (struct lu_client_seq *)data;
	struct lu_client_seq *seq = (struct lu_client_seq *)m->private;
	struct client_obd *cli;
	int rc;
	ENTRY;
@@ -338,23 +197,26 @@ seq_client_proc_read_server(char *page, char **start, off_t off,

	if (seq->lcs_exp != NULL) {
		cli = &seq->lcs_exp->exp_obd->u.cli;
		rc = snprintf(page, count, "%s\n", cli->cl_target_uuid.uuid);
		rc = seq_printf(m, "%s\n", cli->cl_target_uuid.uuid);
	} else {
		rc = snprintf(page, count, "%s\n", seq->lcs_srv->lss_name);
		rc = seq_printf(m, "%s\n", seq->lcs_srv->lss_name);
	}
	RETURN(rc);
}

struct lprocfs_vars seq_server_proc_list[] = {
	{ "space",    seq_server_proc_read_space, seq_server_proc_write_space, NULL },
	{ "width",    seq_server_proc_read_width, seq_server_proc_write_width, NULL },
	{ "server",   seq_server_proc_read_server, NULL, NULL },
	{ NULL }};
};

LPROC_SEQ_FOPS(lprocfs_fid_space);
LPROC_SEQ_FOPS(lprocfs_fid_width);
LPROC_SEQ_FOPS_RO(lprocfs_fid_server);
LPROC_SEQ_FOPS_RO(lprocfs_fid_fid);

struct lprocfs_vars seq_client_proc_list[] = {
	{ "space",    seq_client_proc_read_space, seq_client_proc_write_space, NULL },
	{ "width",    seq_client_proc_read_width, seq_client_proc_write_width, NULL },
	{ "server",   seq_client_proc_read_server, NULL, NULL },
	{ "fid",      seq_client_proc_read_fid, NULL, NULL },
	{ NULL }};
	{ "space", &lprocfs_fid_space_fops },
	{ "width", &lprocfs_fid_width_fops },
	{ "server", &lprocfs_fid_server_fops },
	{ "fid", &lprocfs_fid_fid_fops },
	{ NULL }
};
#endif
+43 −35
Original line number Diff line number Diff line
@@ -58,12 +58,10 @@

#ifdef LPROCFS
static int
fld_proc_read_targets(char *page, char **start, off_t off,
		      int count, int *eof, void *data)
fld_proc_targets_seq_show(struct seq_file *m, void *unused)
{
	struct lu_client_fld *fld = (struct lu_client_fld *)data;
	struct lu_client_fld *fld = (struct lu_client_fld *)m->private;
	struct lu_fld_target *target;
	int total = 0, rc;
	ENTRY;

	LASSERT(fld != NULL);
@@ -71,41 +69,32 @@ fld_proc_read_targets(char *page, char **start, off_t off,
	spin_lock(&fld->lcf_lock);
	list_for_each_entry(target,
				&fld->lcf_targets, ft_chain)
	{
		rc = snprintf(page, count, "%s\n",
			      fld_target_name(target));
		page += rc;
		count -= rc;
		total += rc;
		if (count == 0)
			break;
	}
		seq_printf(m, "%s\n", fld_target_name(target));
	spin_unlock(&fld->lcf_lock);
	RETURN(total);

	RETURN(0);
}

static int
fld_proc_read_hash(char *page, char **start, off_t off,
		   int count, int *eof, void *data)
fld_proc_hash_seq_show(struct seq_file *m, void *unused)
{
	struct lu_client_fld *fld = (struct lu_client_fld *)data;
	int rc;
	struct lu_client_fld *fld = (struct lu_client_fld *)m->private;
	ENTRY;

	LASSERT(fld != NULL);

	spin_lock(&fld->lcf_lock);
	rc = snprintf(page, count, "%s\n", fld->lcf_hash->fh_name);
	seq_printf(m, "%s\n", fld->lcf_hash->fh_name);
	spin_unlock(&fld->lcf_lock);

	RETURN(rc);
	RETURN(0);
}

static int
fld_proc_write_hash(struct file *file, const char *buffer,
		    unsigned long count, void *data)
static ssize_t
fld_proc_hash_seq_write(struct file *file, const char *buffer,
			size_t count, loff_t *off)
{
	struct lu_client_fld *fld = (struct lu_client_fld *)data;
	struct lu_client_fld *fld = ((struct seq_file *)file->private_data)->private;
	struct lu_fld_hash *hash = NULL;
	int i;
	ENTRY;
@@ -134,11 +123,11 @@ fld_proc_write_hash(struct file *file, const char *buffer,
	RETURN(count);
}

static int
fld_proc_write_cache_flush(struct file *file, const char *buffer,
			   unsigned long count, void *data)
static ssize_t
fld_proc_cache_flush_write(struct file *file, const char __user *buffer,
			       size_t count, loff_t *pos)
{
	struct lu_client_fld *fld = (struct lu_client_fld *)data;
	struct lu_client_fld *fld = file->private_data;
	ENTRY;

	LASSERT(fld != NULL);
@@ -150,6 +139,25 @@ fld_proc_write_cache_flush(struct file *file, const char *buffer,
	RETURN(count);
}

static int fld_proc_cache_flush_open(struct inode *inode, struct file *file)
{
	file->private_data = PDE_DATA(inode);
	return 0;
}

static int fld_proc_cache_flush_release(struct inode *inode, struct file *file)
{
	file->private_data = NULL;
	return 0;
}

struct file_operations fld_proc_cache_flush_fops = {
	.owner		= THIS_MODULE,
	.open		= fld_proc_cache_flush_open,
	.write		= fld_proc_cache_flush_write,
	.release	= fld_proc_cache_flush_release,
};

struct fld_seq_param {
	struct lu_env		fsp_env;
	struct dt_it		*fsp_it;
@@ -265,16 +273,14 @@ struct seq_operations fldb_sops = {

static int fldb_seq_open(struct inode *inode, struct file *file)
{
	struct proc_dir_entry	*dp = PDE(inode);
	struct seq_file		*seq;
	struct lu_server_fld    *fld = (struct lu_server_fld *)dp->data;
	struct lu_server_fld    *fld = (struct lu_server_fld *)PDE_DATA(inode);
	struct dt_object	*obj;
	const struct dt_it_ops  *iops;
	struct fld_seq_param    *param = NULL;
	int			env_init = 0;
	int			rc;

	LPROCFS_ENTRY_AND_CHECK(dp);
	rc = seq_open(file, &fldb_sops);
	if (rc)
		GOTO(out, rc);
@@ -311,7 +317,6 @@ static int fldb_seq_open(struct inode *inode, struct file *file)
			lu_env_fini(&param->fsp_env);
		if (param != NULL)
			OBD_FREE_PTR(param);
		LPROCFS_EXIT();
	}
	return rc;
}
@@ -349,10 +354,13 @@ static int fldb_seq_release(struct inode *inode, struct file *file)
struct lprocfs_vars fld_server_proc_list[] = {
	{ NULL }};

LPROC_SEQ_FOPS_RO(fld_proc_targets);
LPROC_SEQ_FOPS(fld_proc_hash);

struct lprocfs_vars fld_client_proc_list[] = {
	{ "targets",     fld_proc_read_targets, NULL, NULL },
	{ "hash",	fld_proc_read_hash, fld_proc_write_hash, NULL },
	{ "cache_flush", NULL, fld_proc_write_cache_flush, NULL },
	{ "targets", &fld_proc_targets_fops },
	{ "hash", &fld_proc_hash_fops },
	{ "cache_flush", &fld_proc_cache_flush_fops },
	{ NULL }};

struct file_operations fld_proc_seq_fops = {
Loading