Commit 0ad699c0 authored by Leon Romanovsky's avatar Leon Romanovsky Committed by Jason Gunthorpe
Browse files

RDMA/core: Simplify restrack interface



In the current implementation, we have one restrack root per-device and
all users are simply providing it directly. Let's simplify the interface
and have callers provide the ib_device and internally access the
restrack_root.

Signed-off-by: default avatarLeon Romanovsky <leonro@mellanox.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
parent 659067b0
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -287,7 +287,7 @@ struct ib_device *_ib_alloc_device(size_t size)
	if (!device)
	if (!device)
		return NULL;
		return NULL;


	rdma_restrack_init(&device->res);
	rdma_restrack_init(device);


	device->dev.class = &ib_class;
	device->dev.class = &ib_class;
	device_initialize(&device->dev);
	device_initialize(&device->dev);
@@ -315,7 +315,7 @@ void ib_dealloc_device(struct ib_device *device)
	WARN_ON(!list_empty(&device->client_data_list));
	WARN_ON(!list_empty(&device->client_data_list));
	WARN_ON(device->reg_state != IB_DEV_UNREGISTERED &&
	WARN_ON(device->reg_state != IB_DEV_UNREGISTERED &&
		device->reg_state != IB_DEV_UNINITIALIZED);
		device->reg_state != IB_DEV_UNINITIALIZED);
	rdma_restrack_clean(&device->res);
	rdma_restrack_clean(device);
	put_device(&device->dev);
	put_device(&device->dev);
}
}
EXPORT_SYMBOL(ib_dealloc_device);
EXPORT_SYMBOL(ib_dealloc_device);
+2 −2
Original line number Original line Diff line number Diff line
@@ -314,7 +314,6 @@ static int fill_res_info(struct sk_buff *msg, struct ib_device *device)
		[RDMA_RESTRACK_CTX] = "ctx",
		[RDMA_RESTRACK_CTX] = "ctx",
	};
	};


	struct rdma_restrack_root *res = &device->res;
	struct nlattr *table_attr;
	struct nlattr *table_attr;
	int ret, i, curr;
	int ret, i, curr;


@@ -328,7 +327,8 @@ static int fill_res_info(struct sk_buff *msg, struct ib_device *device)
	for (i = 0; i < RDMA_RESTRACK_MAX; i++) {
	for (i = 0; i < RDMA_RESTRACK_MAX; i++) {
		if (!names[i])
		if (!names[i])
			continue;
			continue;
		curr = rdma_restrack_count(res, i, task_active_pid_ns(current));
		curr = rdma_restrack_count(device, i,
					   task_active_pid_ns(current));
		ret = fill_res_info_entry(msg, names[i], curr);
		ret = fill_res_info_entry(msg, names[i], curr);
		if (ret)
		if (ret)
			goto err;
			goto err;
+21 −5
Original line number Original line Diff line number Diff line
@@ -18,8 +18,14 @@ static int fill_res_noop(struct sk_buff *msg,
	return 0;
	return 0;
}
}


void rdma_restrack_init(struct rdma_restrack_root *res)
/**
 * rdma_restrack_init() - initialize resource tracking
 * @dev:  IB device
 */
void rdma_restrack_init(struct ib_device *dev)
{
{
	struct rdma_restrack_root *res = &dev->res;

	init_rwsem(&res->rwsem);
	init_rwsem(&res->rwsem);
	res->fill_res_entry = fill_res_noop;
	res->fill_res_entry = fill_res_noop;
}
}
@@ -38,11 +44,15 @@ static const char *type2str(enum rdma_restrack_type type)
	return names[type];
	return names[type];
};
};


void rdma_restrack_clean(struct rdma_restrack_root *res)
/**
 * rdma_restrack_clean() - clean resource tracking
 * @dev:  IB device
 */
void rdma_restrack_clean(struct ib_device *dev)
{
{
	struct rdma_restrack_root *res = &dev->res;
	struct rdma_restrack_entry *e;
	struct rdma_restrack_entry *e;
	char buf[TASK_COMM_LEN];
	char buf[TASK_COMM_LEN];
	struct ib_device *dev;
	const char *owner;
	const char *owner;
	int bkt;
	int bkt;


@@ -72,10 +82,16 @@ void rdma_restrack_clean(struct rdma_restrack_root *res)
	pr_err("restrack: %s", CUT_HERE);
	pr_err("restrack: %s", CUT_HERE);
}
}


int rdma_restrack_count(struct rdma_restrack_root *res,
/**
			enum rdma_restrack_type type,
 * rdma_restrack_count() - the current usage of specific object
 * @dev:  IB device
 * @type: actual type of object to operate
 * @ns:   PID namespace
 */
int rdma_restrack_count(struct ib_device *dev, enum rdma_restrack_type type,
			struct pid_namespace *ns)
			struct pid_namespace *ns)
{
{
	struct rdma_restrack_root *res = &dev->res;
	struct rdma_restrack_entry *e;
	struct rdma_restrack_entry *e;
	u32 cnt = 0;
	u32 cnt = 0;


+4 −19
Original line number Original line Diff line number Diff line
@@ -49,6 +49,7 @@ enum rdma_restrack_type {
};
};


#define RDMA_RESTRACK_HASH_BITS	8
#define RDMA_RESTRACK_HASH_BITS	8
struct ib_device;
struct rdma_restrack_entry;
struct rdma_restrack_entry;


/**
/**
@@ -122,25 +123,9 @@ struct rdma_restrack_entry {
	bool			user;
	bool			user;
};
};


/**
void rdma_restrack_init(struct ib_device *dev);
 * rdma_restrack_init() - initialize resource tracking
void rdma_restrack_clean(struct ib_device *dev);
 * @res:  resource tracking root
int rdma_restrack_count(struct ib_device *dev,
 */
void rdma_restrack_init(struct rdma_restrack_root *res);

/**
 * rdma_restrack_clean() - clean resource tracking
 * @res:  resource tracking root
 */
void rdma_restrack_clean(struct rdma_restrack_root *res);

/**
 * rdma_restrack_count() - the current usage of specific object
 * @res:  resource entry
 * @type: actual type of object to operate
 * @ns:   PID namespace
 */
int rdma_restrack_count(struct rdma_restrack_root *res,
			enum rdma_restrack_type type,
			enum rdma_restrack_type type,
			struct pid_namespace *ns);
			struct pid_namespace *ns);