scst/include/backport.h: Add a kref_read() backport

This patch does not change any functionality.


git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7178 d57e44dd-8a1f-0410-8b47-8ef2f437770f
This commit is contained in:
Bart Van Assche
2017-05-14 03:06:54 +00:00
parent 4a18e68c3f
commit b4118ea0f1
5 changed files with 6 additions and 19 deletions

View File

@@ -482,11 +482,7 @@ static void ft_sess_free(struct kref *kref)
static void ft_sess_put(struct ft_sess *sess)
{
BUG_ON(!sess);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
BUG_ON(kref_read(&sess->kref) <= 0);
#else
BUG_ON(atomic_read(&sess->kref.refcount) <= 0);
#endif
kref_put(&sess->kref, ft_sess_free);
}

View File

@@ -1402,11 +1402,7 @@ static void isert_kref_free(struct kref *kref)
void isert_conn_free(struct isert_connection *isert_conn)
{
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
sBUG_ON(kref_read(&isert_conn->kref) == 0);
#else
sBUG_ON(atomic_read(&isert_conn->kref.refcount) == 0);
#endif
kref_put(&isert_conn->kref, isert_kref_free);
}

View File

@@ -113,11 +113,7 @@ static void isert_kref_release_dev(struct kref *kref)
static void isert_dev_release(struct isert_conn_dev *dev)
{
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
sBUG_ON(kref_read(&dev->kref) == 0);
#else
sBUG_ON(atomic_read(&dev->kref.refcount) == 0);
#endif
mutex_lock(&isert_listen_dev.conn_lock);
kref_put(&dev->kref, isert_kref_release_dev);
mutex_unlock(&isert_listen_dev.conn_lock);

View File

@@ -361,6 +361,11 @@ static inline int __must_check kref_get_unless_zero(struct kref *kref)
}
#endif
/* See also commit 2c935bc57221 */
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 11, 0)
#define kref_read(kref) (atomic_read(&(kref)->refcount))
#endif
/* <linux/kthread.h> */
/* See also commit 207205a2ba26 */

View File

@@ -1203,13 +1203,7 @@ void scst_kobject_put_and_wait(struct kobject *kobj, const char *category,
goto out_free;
PRINT_INFO("Waiting for release of sysfs entry for %s %s (%d refs)",
category, name ? : "(?)",
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
kref_read(&kobj->kref)
#else
atomic_read(&kobj->kref.refcount)
#endif
);
category, name ? : "(?)", kref_read(&kobj->kref));
wait_for_completion(c);
PRINT_INFO("Finished waiting for release of %s %s sysfs entry",
category, name ? : "(?)");