vhost_net: Use fdget() and fdput()
Subsystems (5)
PATCH 1/1 vhost_net: Use fdget() and fdput()
From: Ye Xingchen <[email protected]>
convert the fget()/fput() uses to fdget()/fdput().
--- drivers/vhost/net.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/vhost/net.c +5 -5
@@ -1466,17 +1466,17 @@ static struct ptr_ring *get_tap_ptr_ring(struct file *file)static struct socket *get_tap_socket (int fd) { -struct file *file =fget (fd); +struct fd f =fdget (fd);struct socket *sock; -if (!file) +if (!f.file)return ERR_PTR (-EBADF ); - sock =tun_get_socket (file); + sock =tun_get_socket (f.file);if (!IS_ERR (sock))return sock; - sock =tap_get_socket (file); + sock =tap_get_socket (f.file);if (IS_ERR (sock)) -fput (file); +fdput (f);return sock; }
Signature · 1 line
2.25.1
Quoted 4 lines · On Fri, May 5, 2023 at 2:24 PM <[email protected]> wrote:
From: Ye Xingchen <[email protected]>
convert the fget()/fput() uses to fdget()/fdput().
What's the advantages of this?
Thanks
Quoted 36 lines
Signed-off-by Ye Xingchen <[email protected]>--- drivers/vhost/net.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)drivers/vhost/net.c +5
-6@@ -1466,17 +1466,17 @@ static struct ptr_ring *get_tap_ptr_ring(struct file *file)static struct socket *get_tap_socket (int fd) { -struct file *file =fget (fd); +struct fd f =fdget (fd);struct socket *sock; -if (!file) +if (!f.file)return ERR_PTR (-EBADF ); - sock =tun_get_socket (file); + sock =tun_get_socket (f.file);if (!IS_ERR (sock))return sock; - sock =tap_get_socket (file); + sock =tap_get_socket (f.file);if (IS_ERR (sock)) -fput (file); +fdput (f);return sock; } --2.25.1
Quoted 40 lines
Quoted 4 lines
From: Ye Xingchen <[email protected]>
convert the fget()/fput() uses to fdget()/fdput().
What's the advantages of this?
Thanks
Quoted 33 lines
Signed-off-by Ye Xingchen <[email protected]>--- drivers/vhost/net.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)drivers/vhost/net.c +5
-5@@ -1466,17 +1466,17 @@ static struct ptr_ring *get_tap_ptr_ring(struct file *file)static struct socket *get_tap_socket (int fd) { -struct file *file =fget (fd); +struct fd f =fdget (fd);struct socket *sock; -if (!file) +if (!f.file)return ERR_PTR (-EBADF ); - sock =tun_get_socket (file); + sock =tun_get_socket (f.file);if (!IS_ERR (sock))return sock; - sock =tap_get_socket (file); + sock =tap_get_socket (f.file);if (IS_ERR (sock)) -fput (file); +fdput (f);return sock; }
Quoted 3 lines
Quoted 3 lines
--
2.25.1
fdget requires an integer type file descriptor as its parameter, and fget requires a pointer to the file structure as its parameter.
By using the fdget function, the socket object, can be quickly obtained from the process's file descriptor table without the need to obtain the file descriptor first before passing it as a parameter to the fget function. This reduces unnecessary operations, improves system efficiency and performance.
Best Regards
Ye
Michael S. Tsirkin
maintainerQuoted 40 lines · ye xingchen
Quoted 40 lines
Quoted 4 lines
From: Ye Xingchen <[email protected]>
convert the fget()/fput() uses to fdget()/fdput().
What's the advantages of this?
Thanks
Quoted 33 lines
Signed-off-by Ye Xingchen <[email protected]>--- drivers/vhost/net.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)drivers/vhost/net.c +5
-5@@ -1466,17 +1466,17 @@ static struct ptr_ring *get_tap_ptr_ring(struct file *file)static struct socket *get_tap_socket (int fd) { -struct file *file =fget (fd); +struct fd f =fdget (fd);struct socket *sock; -if (!file) +if (!f.file)return ERR_PTR (-EBADF ); - sock =tun_get_socket (file); + sock =tun_get_socket (f.file);if (!IS_ERR (sock))return sock; - sock =tap_get_socket (file); + sock =tap_get_socket (f.file);if (IS_ERR (sock)) -fput (file); +fdput (f);return sock; }
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
--
2.25.1fdget requires an integer type file descriptor as its parameter, and fget requires a pointer to the file structure as its parameter.
In which kernel?
include/linux/file.h:extern struct file *fget(unsigned int fd);
Quoted 8 lines
By using the fdget function, the socket object, can be quickly obtained from the process's file descriptor table without the need to obtain the file descriptor first before passing it as a parameter to the fget function. This reduces unnecessary operations, improves system efficiency and performance.
Best Regards
Ye
Quoted 24 lines · On Fri, May 05, 2023 at 02:24:04PM +0800, [email protected] wrote:
From: Ye Xingchen <[email protected]>
convert the fget()/fput() uses to fdget()/fdput().
Signed-off-by Ye Xingchen <[email protected]>--- drivers/vhost/net.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)drivers/vhost/net.c +2
-2@@ -1466,17 +1466,17 @@ static struct ptr_ring *get_tap_ptr_ring(struct file *file)static struct socket *get_tap_socket (int fd) { -struct file *file =fget (fd); +struct fd f =fdget (fd);struct socket *sock; -if (!file) +if (!f.file)return ERR_PTR (-EBADF );
drivers/vhost/net.c static struct ptr_ring *get_tap_ptr_ring(struct file *file) · line 1480
Quoted 10 lines
drivers/vhost/net.c +3
-3- sock =tun_get_socket (file); + sock =tun_get_socket (f.file);if (!IS_ERR (sock))return sock; - sock =tap_get_socket (file); + sock =tap_get_socket (f.file);if (IS_ERR (sock)) -fput (file); +fdput (f);return sock;
NAK. For the same reason why the sockfd_lookup() counterpart of that patch is broken. After your change there's no way for the caller to tell whether we have bumped the refcount of file in question; this can't possibly work.