From: Wang Wensheng wangwensheng4@huawei.com
The user need to release the resoucrces if the associated POOL was destroyed, so return the POOL exist-status in unregister operation.
Signed-off-by: Wang Wensheng wangwensheng4@huawei.com --- include/uapi/linux/xshmem_framework.h | 3 +++ lib/xshmem/xshmem_framework.c | 12 +++++++----- 2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/include/uapi/linux/xshmem_framework.h b/include/uapi/linux/xshmem_framework.h index 07181d7..205c928 100644 --- a/include/uapi/linux/xshmem_framework.h +++ b/include/uapi/linux/xshmem_framework.h @@ -35,4 +35,7 @@ struct xshm_block_arg { #define XSHMEM_ALGO_BLOCK 0 #define XSHMEM_ALGO_FSC 1
+#define XSHMEM_POOL_STATUS_DELETE 0 +#define XSHMEM_POOL_STATUS_EXIST 1 + #endif diff --git a/lib/xshmem/xshmem_framework.c b/lib/xshmem/xshmem_framework.c index 46fefb8..97c44e3 100644 --- a/lib/xshmem/xshmem_framework.c +++ b/lib/xshmem/xshmem_framework.c @@ -289,12 +289,12 @@ static struct xshm_pool *xshmem_pool_get(int pool_id) return xp; }
-static void xshmem_pool_put(struct xshm_pool *xp) +static int xshmem_pool_put(struct xshm_pool *xp) { mutex_lock(&xshmem_mutex); if (!atomic_dec_and_test(&xp->refcnt)) { mutex_unlock(&xshmem_mutex); - return; + return XSHMEM_POOL_STATUS_EXIST; }
hlist_del(&xp->hnode); @@ -305,6 +305,8 @@ static void xshmem_pool_put(struct xshm_pool *xp)
xp->algo->xshm_pool_free(xp); kfree(xp); + + return XSHMEM_POOL_STATUS_DELETE; }
static int ioctl_xshmem_pool_register(struct xshm_task *task, unsigned long arg) @@ -351,7 +353,7 @@ static int ioctl_xshmem_pool_register(struct xshm_task *task, unsigned long arg)
static int ioctl_xshmem_pool_unregister(struct xshm_task *task, unsigned long arg) { - int ret; + int ret, state; struct xshm_pool *xp;
xp = xshmem_pool_get(arg); @@ -362,9 +364,9 @@ static int ioctl_xshmem_pool_unregister(struct xshm_task *task, unsigned long ar
ret = xshmem_pool_detach(task, xp);
- xshmem_pool_put(xp); + state = xshmem_pool_put(xp);
- return ret; + return ret < 0 ? ret : state; }
/* The caller must hold xp->xp_block_mutex */