linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiang Wang <jiang.wang@bytedance.com>
To: jiangleetcode@gmail.com
Cc: virtualization@lists.linux-foundation.org, stefanha@redhat.com,
	sgarzare@redhat.com, mst@redhat.com,
	arseny.krasnov@kaspersky.com, jhansen@vmware.com,
	cong.wang@bytedance.com, duanxiongchun@bytedance.com,
	xieyongji@bytedance.com, chaiwen.cc@bytedance.com,
	Jason Wang <jasowang@redhat.com>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ingo Molnar <mingo@redhat.com>,
	kvm@vger.kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [RFC v2 5/5] virtio/vsock: add sysfs for rx buf len for dgram
Date: Tue, 14 Sep 2021 05:54:38 +0000	[thread overview]
Message-ID: <20210914055440.3121004-6-jiang.wang@bytedance.com> (raw)
In-Reply-To: <20210914055440.3121004-1-jiang.wang@bytedance.com>

Make rx buf len configurable via sysfs

Signed-off-by: Jiang Wang <jiang.wang@bytedance.com>
---
 net/vmw_vsock/virtio_transport.c | 46 ++++++++++++++++++++++++++++++--
 1 file changed, 44 insertions(+), 2 deletions(-)

diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c
index 8d5bfcd79555..55216d979080 100644
--- a/net/vmw_vsock/virtio_transport.c
+++ b/net/vmw_vsock/virtio_transport.c
@@ -29,6 +29,16 @@ static struct virtio_vsock __rcu *the_virtio_vsock;
 static struct virtio_vsock *the_virtio_vsock_dgram;
 static DEFINE_MUTEX(the_virtio_vsock_mutex); /* protects the_virtio_vsock */
 
+static int rx_buf_len = VIRTIO_VSOCK_DEFAULT_RX_BUF_SIZE;
+static struct kobject *kobj_ref, *kobj_ref2;
+static ssize_t  dgram_sysfs_show(struct kobject *kobj,
+				 struct kobj_attribute *attr, char *buf);
+static ssize_t  dgram_sysfs_store(struct kobject *kobj,
+				  struct kobj_attribute *attr, const char *buf,
+				  size_t count);
+static struct kobj_attribute rxbuf_attr = __ATTR(dgram_rx_buf_size, 0660, dgram_sysfs_show,
+						 dgram_sysfs_store);
+
 struct virtio_vsock {
 	struct virtio_device *vdev;
 	struct virtqueue **vqs;
@@ -362,7 +372,7 @@ virtio_transport_cancel_pkt(struct vsock_sock *vsk)
 
 static void virtio_vsock_rx_fill(struct virtio_vsock *vsock, bool is_dgram)
 {
-	int buf_len = VIRTIO_VSOCK_DEFAULT_RX_BUF_SIZE;
+	int buf_len = rx_buf_len;
 	struct virtio_vsock_pkt *pkt;
 	struct scatterlist hdr, buf, *sgs[2];
 	struct virtqueue *vq;
@@ -1027,6 +1037,23 @@ static struct virtio_driver virtio_vsock_driver = {
 	.remove = virtio_vsock_remove,
 };
 
+static ssize_t dgram_sysfs_show(struct kobject *kobj,
+				struct kobj_attribute *attr, char *buf)
+{
+	return sprintf(buf, "%d", rx_buf_len);
+}
+
+static ssize_t dgram_sysfs_store(struct kobject *kobj,
+				 struct kobj_attribute *attr, const char *buf,
+				 size_t count)
+{
+	if (kstrtou32(buf, 0, &rx_buf_len) < 0)
+		return -EINVAL;
+	if (rx_buf_len < 1024)
+		rx_buf_len = 1024;
+	return count;
+}
+
 static int __init virtio_vsock_init(void)
 {
 	int ret;
@@ -1044,8 +1071,19 @@ static int __init virtio_vsock_init(void)
 	if (ret)
 		goto out_vci;
 
-	return 0;
+	kobj_ref = kobject_create_and_add("vsock", kernel_kobj);
+	kobj_ref2 = kobject_create_and_add("virtio", kobj_ref);
+
+	/*Creating sysfs file for etx_value*/
+	ret = sysfs_create_file(kobj_ref2, &rxbuf_attr.attr);
+	if (ret)
+		goto out_sysfs;
 
+	return 0;
+out_sysfs:
+	kobject_put(kobj_ref);
+	kobject_put(kobj_ref2);
+	sysfs_remove_file(kobj_ref2, &rxbuf_attr.attr);
 out_vci:
 	vsock_core_unregister(&virtio_transport.transport);
 out_wq:
@@ -1058,6 +1096,10 @@ static void __exit virtio_vsock_exit(void)
 	unregister_virtio_driver(&virtio_vsock_driver);
 	vsock_core_unregister(&virtio_transport.transport);
 	destroy_workqueue(virtio_vsock_workqueue);
+	kobject_put(kobj_ref);
+	kobject_put(kobj_ref2);
+	sysfs_remove_file(kobj_ref2, &rxbuf_attr.attr);
+
 }
 
 module_init(virtio_vsock_init);
-- 
2.20.1


      parent reply	other threads:[~2021-09-14  5:56 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-14  5:54 [RFC v2 0/5] virtio/vsock: introduce SOCK_DGRAM support Jiang Wang
2021-09-14  5:54 ` [RFC v2 1/5] virtio/vsock: add VIRTIO_VSOCK_F_DGRAM feature bit Jiang Wang
2021-09-14  5:54 ` [RFC v2 2/5] virtio/vsock: add support for virtio datagram Jiang Wang
2021-09-14  6:56   ` Michael S. Tsirkin
2021-09-14  5:54 ` [RFC v2 3/5] vhost/vsock: add support for vhost dgram Jiang Wang
2021-09-14  6:52   ` Michael S. Tsirkin
2021-09-14  5:54 ` [RFC v2 4/5] vsock_test: add tests for vsock dgram Jiang Wang
2021-09-14  5:54 ` Jiang Wang [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210914055440.3121004-6-jiang.wang@bytedance.com \
    --to=jiang.wang@bytedance.com \
    --cc=arseny.krasnov@kaspersky.com \
    --cc=chaiwen.cc@bytedance.com \
    --cc=cong.wang@bytedance.com \
    --cc=davem@davemloft.net \
    --cc=duanxiongchun@bytedance.com \
    --cc=jasowang@redhat.com \
    --cc=jhansen@vmware.com \
    --cc=jiangleetcode@gmail.com \
    --cc=kuba@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=sgarzare@redhat.com \
    --cc=stefanha@redhat.com \
    --cc=virtualization@lists.linux-foundation.org \
    --cc=xieyongji@bytedance.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).