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

Commit abf9e661 authored by Murali Nalajala's avatar Murali Nalajala Committed by Prakruthi Deepak Heragu
Browse files

vservices: core: Port core vservices drivers to linux 4.14



Vservices core drivers are broken on 4.14 kernel due to core
framework changes.This commit updates the virtual services
core to build and run on linux 4.14.

Change-Id: I53360a8b8431d58c4569d4d4c3b86f3c820b6faf
Signed-off-by: default avatarMurali Nalajala <mnalajal@codeaurora.org>
Signed-off-by: default avatarPrakruthi Deepak Heragu <pheragu@codeaurora.org>
parent f17bb74f
Loading
Loading
Loading
Loading
+22 −20
Original line number Diff line number Diff line
@@ -511,6 +511,8 @@ static ssize_t is_server_show(struct device *dev, struct device_attribute *attr,
	return scnprintf(buf, PAGE_SIZE, "%d\n", service->is_server);
}

static DEVICE_ATTR_RO(is_server);

static ssize_t id_show(struct device *dev, struct device_attribute *attr,
		char *buf)
{
@@ -519,6 +521,8 @@ static ssize_t id_show(struct device *dev, struct device_attribute *attr,
	return scnprintf(buf, PAGE_SIZE, "%d\n", service->id);
}

static DEVICE_ATTR_RO(id);

static ssize_t dev_protocol_show(struct device *dev,
		struct device_attribute *attr, char *buf)
{
@@ -527,6 +531,8 @@ static ssize_t dev_protocol_show(struct device *dev,
	return scnprintf(buf, PAGE_SIZE, "%s\n", service->protocol ?: "");
}

static DEVICE_ATTR(protocol, 0444, dev_protocol_show, NULL);

static ssize_t service_name_show(struct device *dev,
		struct device_attribute *attr, char *buf)
{
@@ -535,6 +541,8 @@ static ssize_t service_name_show(struct device *dev,
	return scnprintf(buf, PAGE_SIZE, "%s\n", service->name);
}

static DEVICE_ATTR_RO(service_name);

static ssize_t quota_in_show(struct device *dev,
		struct device_attribute *attr, char *buf)
{
@@ -543,6 +551,8 @@ static ssize_t quota_in_show(struct device *dev,
	return scnprintf(buf, PAGE_SIZE, "%d\n", service->send_quota);
}

static DEVICE_ATTR_RO(quota_in);

static ssize_t quota_out_show(struct device *dev,
		struct device_attribute *attr, char *buf)
{
@@ -551,15 +561,18 @@ static ssize_t quota_out_show(struct device *dev,
	return scnprintf(buf, PAGE_SIZE, "%d\n", service->recv_quota);
}

static struct device_attribute vs_client_dev_attrs[] = {
	__ATTR_RO(id),
	__ATTR_RO(is_server),
	__ATTR(protocol, S_IRUGO, dev_protocol_show, NULL),
	__ATTR_RO(service_name),
	__ATTR_RO(quota_in),
	__ATTR_RO(quota_out),
	__ATTR_NULL
static DEVICE_ATTR_RO(quota_out);

static struct attribute *vs_client_dev_attrs[] = {
	&dev_attr_id.attr,
	&dev_attr_is_server.attr,
	&dev_attr_protocol.attr,
	&dev_attr_service_name.attr,
	&dev_attr_quota_in.attr,
	&dev_attr_quota_out.attr,
	NULL,
};
ATTRIBUTE_GROUPS(vs_client_dev);

static ssize_t protocol_show(struct device_driver *drv, char *buf)
{
@@ -568,12 +581,6 @@ static ssize_t protocol_show(struct device_driver *drv, char *buf)
	return scnprintf(buf, PAGE_SIZE, "%s\n", driver->protocol);
}

#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0)
static struct driver_attribute vs_client_drv_attrs[] = {
	__ATTR_RO(protocol),
	__ATTR_NULL
};
#else
static DRIVER_ATTR_RO(protocol);

static struct attribute *vs_client_drv_attrs[] = {
@@ -581,16 +588,11 @@ static struct attribute *vs_client_drv_attrs[] = {
	NULL,
};
ATTRIBUTE_GROUPS(vs_client_drv);
#endif

struct bus_type vs_client_bus_type = {
	.name		= "vservices-client",
	.dev_attrs	= vs_client_dev_attrs,
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0)
	.drv_attrs	= vs_client_drv_attrs,
#else
	.dev_groups	= vs_client_dev_groups,
	.drv_groups	= vs_client_drv_groups,
#endif
	.match		= vs_client_bus_match,
	.probe		= vs_service_bus_probe,
	.remove		= vs_service_bus_remove,
+23 −23
Original line number Diff line number Diff line
@@ -1214,6 +1214,8 @@ static ssize_t is_server_show(struct device *dev, struct device_attribute *attr,
	return scnprintf(buf, PAGE_SIZE, "%d\n", service->is_server);
}

static DEVICE_ATTR_RO(is_server);

static ssize_t id_show(struct device *dev, struct device_attribute *attr,
		char *buf)
{
@@ -1222,6 +1224,8 @@ static ssize_t id_show(struct device *dev, struct device_attribute *attr,
	return scnprintf(buf, PAGE_SIZE, "%d\n", service->id);
}

static DEVICE_ATTR_RO(id);

static ssize_t dev_protocol_show(struct device *dev,
		struct device_attribute *attr, char *buf)
{
@@ -1319,6 +1323,9 @@ static ssize_t dev_protocol_store(struct device *dev,
	return count;
}

static DEVICE_ATTR(protocol, 0644,
				dev_protocol_show, dev_protocol_store);

static ssize_t service_name_show(struct device *dev,
		struct device_attribute *attr, char *buf)
{
@@ -1327,6 +1334,8 @@ static ssize_t service_name_show(struct device *dev,
	return scnprintf(buf, PAGE_SIZE, "%s\n", service->name);
}

static DEVICE_ATTR_RO(service_name);

static ssize_t quota_in_store(struct device *dev,
		struct device_attribute *attr, const char *buf, size_t count)
{
@@ -1373,6 +1382,8 @@ static ssize_t quota_in_show(struct device *dev,
	return scnprintf(buf, PAGE_SIZE, "%u\n", service->recv_quota);
}

static DEVICE_ATTR_RW(quota_in);

static ssize_t quota_out_store(struct device *dev,
		struct device_attribute *attr, const char *buf, size_t count)
{
@@ -1412,18 +1423,18 @@ static ssize_t quota_out_show(struct device *dev,
	return scnprintf(buf, PAGE_SIZE, "%u\n", service->send_quota);
}

static struct device_attribute vs_server_dev_attrs[] = {
	__ATTR_RO(id),
	__ATTR_RO(is_server),
	__ATTR(protocol, S_IRUGO | S_IWUSR,
			dev_protocol_show, dev_protocol_store),
	__ATTR_RO(service_name),
	__ATTR(quota_in, S_IRUGO | S_IWUSR,
			quota_in_show, quota_in_store),
	__ATTR(quota_out, S_IRUGO | S_IWUSR,
			quota_out_show, quota_out_store),
	__ATTR_NULL
static DEVICE_ATTR_RW(quota_out);

static struct attribute *vs_server_dev_attrs[] = {
	&dev_attr_id.attr,
	&dev_attr_is_server.attr,
	&dev_attr_protocol.attr,
	&dev_attr_service_name.attr,
	&dev_attr_quota_in.attr,
	&dev_attr_quota_out.attr,
	NULL,
};
ATTRIBUTE_GROUPS(vs_server_dev);

static ssize_t protocol_show(struct device_driver *drv, char *buf)
{
@@ -1432,12 +1443,6 @@ static ssize_t protocol_show(struct device_driver *drv, char *buf)
	return scnprintf(buf, PAGE_SIZE, "%s\n", vsdrv->protocol);
}

#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0)
static struct driver_attribute vs_server_drv_attrs[] = {
	__ATTR_RO(protocol),
	__ATTR_NULL
};
#else
static DRIVER_ATTR_RO(protocol);

static struct attribute *vs_server_drv_attrs[] = {
@@ -1445,16 +1450,11 @@ static struct attribute *vs_server_drv_attrs[] = {
	NULL,
};
ATTRIBUTE_GROUPS(vs_server_drv);
#endif

struct bus_type vs_server_bus_type = {
	.name		= "vservices-server",
	.dev_attrs	= vs_server_dev_attrs,
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0)
	.drv_attrs	= vs_server_drv_attrs,
#else
	.dev_groups	= vs_server_dev_groups,
	.drv_groups	= vs_server_drv_groups,
#endif
	.match		= vs_server_bus_match,
	.probe		= vs_server_bus_probe,
	.remove		= vs_server_bus_remove,
+1 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@
#include <vservices/session.h>
#include <vservices/service.h>
#include <vservices/ioctl.h>
#include <linux/sched/signal.h>
#include "session.h"

#define VSERVICES_DEVICE_MAX (VS_MAX_SERVICES * VS_MAX_SESSIONS)
+26 −94
Original line number Diff line number Diff line
@@ -1149,7 +1149,7 @@ static void service_rx_work(struct work_struct *work)
 * read only, so we use a generator macro to avoid code duplication.
 */
#define service_stat_attr(__name)						\
	static ssize_t service_stat_##__name##_show(struct device *dev, \
	static ssize_t __name##_show(struct device *dev,	\
			struct device_attribute *attr, char *buf)	\
	{													\
		struct vs_service_device *service =				\
@@ -1158,8 +1158,7 @@ static void service_rx_work(struct work_struct *work)
		return scnprintf(buf, PAGE_SIZE, "%u\n",		\
				atomic_read(&service->stats.__name));	\
	}													\
	static DEVICE_ATTR(__name, S_IRUGO,                             \
			service_stat_##__name##_show, NULL);
	static DEVICE_ATTR_RO(__name)

service_stat_attr(sent_mbufs);
service_stat_attr(sent_bytes);
@@ -1364,41 +1363,6 @@ static void vs_service_release(struct device *dev)
static int service_add_idr(struct vs_session_device *session,
		struct vs_service_device *service, vs_service_id_t service_id)
{
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0)
	int err, base_id, id;

	if (service_id == VS_SERVICE_AUTO_ALLOCATE_ID)
		base_id = 1;
	else
		base_id = service_id;

retry:
	if (!idr_pre_get(&session->service_idr, GFP_KERNEL))
		return -ENOMEM;

	mutex_lock(&session->service_idr_lock);
	err = idr_get_new_above(&session->service_idr, service, base_id, &id);
	if (err == 0) {
		if (service_id != VS_SERVICE_AUTO_ALLOCATE_ID &&
				id != service_id) {
			/* Failed to allocated the requested service id */
			idr_remove(&session->service_idr, id);
			mutex_unlock(&session->service_idr_lock);
			return -EBUSY;
		}
		if (id > VS_MAX_SERVICE_ID) {
			/* We are out of service ids */
			idr_remove(&session->service_idr, id);
			mutex_unlock(&session->service_idr_lock);
			return -ENOSPC;
		}
	}
	mutex_unlock(&session->service_idr_lock);
	if (err == -EAGAIN)
		goto retry;
	if (err < 0)
		return err;
#else
	int start, end, id;

	if (service_id == VS_SERVICE_AUTO_ALLOCATE_ID) {
@@ -1418,7 +1382,6 @@ static int service_add_idr(struct vs_session_device *session,
		return -EBUSY;
	else if (id < 0)
		return id;
#endif

	service->id = id;
	return 0;
@@ -1589,23 +1552,7 @@ struct vs_service_device *vs_service_register(struct vs_session_device *session,
		 * anything like lock_nested() for it.
		 */

#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 3, 0)
		/*
		 * Lockdep allows a specific lock's subclass to be set with
		 * the subclass argument to lockdep_init_map(). However, prior
		 * to Linux 3.3, that only works the first time it is called
		 * for a given class and subclass. So we have to fake it,
		 * putting every subclass in a different class, so the only
		 * thing that breaks is printing the subclass in lockdep
		 * warnings.
		 */
		static struct lock_class_key
				rx_work_keys[MAX_LOCKDEP_SUBCLASSES];
		struct lock_class_key *key =
				&rx_work_keys[service->lock_subclass];
#else
		struct lock_class_key *key = service->rx_work.lockdep_map.key;
#endif

		/*
		 * We can't use the lockdep_set_class() macro because the
@@ -2371,6 +2318,8 @@ static ssize_t id_show(struct device *dev,
	return scnprintf(buf, PAGE_SIZE, "%d\n", session->session_num);
}

static DEVICE_ATTR_RO(id);

/*
 * The vServices session device type
 */
@@ -2382,6 +2331,8 @@ static ssize_t is_server_show(struct device *dev,
	return scnprintf(buf, PAGE_SIZE, "%d\n", session->is_server);
}

static DEVICE_ATTR_RO(is_server);

static ssize_t name_show(struct device *dev,
		struct device_attribute *attr, char *buf)
{
@@ -2390,6 +2341,8 @@ static ssize_t name_show(struct device *dev,
	return scnprintf(buf, PAGE_SIZE, "%s\n", session->name);
}

static DEVICE_ATTR_RO(name);

#ifdef CONFIG_VSERVICES_DEBUG
static ssize_t debug_mask_show(struct device *dev,
		struct device_attribute *attr, char *buf)
@@ -2414,18 +2367,21 @@ static ssize_t debug_mask_store(struct device *dev,

	return count;
}

static DEVICE_ATTR_RW(debug_mask);

#endif /* CONFIG_VSERVICES_DEBUG */

static struct device_attribute vservices_session_dev_attrs[] = {
	__ATTR_RO(id),
	__ATTR_RO(is_server),
	__ATTR_RO(name),
static struct attribute *vservices_session_dev_attrs[] = {
	&dev_attr_id.attr,
	&dev_attr_is_server.attr,
	&dev_attr_name.attr,
#ifdef CONFIG_VSERVICES_DEBUG
	__ATTR(debug_mask, S_IRUGO | S_IWUSR,
			debug_mask_show, debug_mask_store),
	&dev_attr_debug_mask.attr,
#endif
	__ATTR_NULL,
	NULL,
};
ATTRIBUTE_GROUPS(vservices_session_dev);

static int vs_session_free_idr(struct vs_session_device *session)
{
@@ -2521,7 +2477,7 @@ struct bus_type vs_session_bus_type = {
	.name		= "vservices-session",
	.match		= vs_session_bus_match,
	.remove		= vs_session_bus_remove,
	.dev_attrs	= vservices_session_dev_attrs,
	.dev_groups	= vservices_session_dev_groups,
	.uevent		= vservices_session_uevent,
	.shutdown	= vservices_session_shutdown,
};
@@ -2653,29 +2609,6 @@ static int vs_session_create_sysfs_entry(struct vs_transport *transport,

static int vs_session_alloc_idr(struct vs_session_device *session)
{
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0)
	int err, id;

retry:
	if (!idr_pre_get(&session_idr, GFP_KERNEL))
		return -ENOMEM;

	mutex_lock(&vs_session_lock);
	err = idr_get_new_above(&session_idr, session, 0, &id);
	if (err == 0) {
		if (id >= VS_MAX_SESSIONS) {
			/* We are out of session ids */
			idr_remove(&session_idr, id);
			mutex_unlock(&vs_session_lock);
			return -EBUSY;
		}
	}
	mutex_unlock(&vs_session_lock);
	if (err == -EAGAIN)
		goto retry;
	if (err < 0)
		return err;
#else
	int id;

	mutex_lock(&vs_session_lock);
@@ -2686,7 +2619,6 @@ static int vs_session_alloc_idr(struct vs_session_device *session)
		return -EBUSY;
	else if (id < 0)
		return id;
#endif

	session->session_num = id;
	return 0;
+2 −2
Original line number Diff line number Diff line
@@ -590,10 +590,10 @@ __releases(&service->state_spinlock)
	struct vs_service_device *__service = __state->service;		\
	mutex_lock_nested(&__service->ready_lock,			\
			__service->lock_subclass);			\
	__ok = !ACCESS_ONCE(__state->released);				\
	__ok = !READ_ONCE(__state->released);				\
	if (__ok) {							\
		_lock(__state);						\
		__ok = !ACCESS_ONCE(__state->released);			\
		__ok = !READ_ONCE(__state->released);			\
		if (!__ok)						\
			_unlock(__state);				\
	}								\
Loading