Skip to content

Commit 84fc461

Browse files
committed
Merge tag 'for-linus-5.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rw/uml
Pull UML updates from Richard Weinberger: - Use fdatasync() in ubd - Add a generic "fd" vector transport - Minor cleanups and fixes * tag 'for-linus-5.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rw/uml: um: virtio: Replace zero-length array with flexible-array um: Use fdatasync() when mapping the UBD FSYNC command um: Do not evaluate compiler's library path when cleaning um: Neaten vu_err macro definition um: Add a generic "fd" vector transport um: Add include: memset() and memcpy() are in <string.h>
2 parents 0e083da + f6e8c47 commit 84fc461

File tree

5 files changed

+64
-4
lines changed

5 files changed

+64
-4
lines changed

arch/um/drivers/vector_kern.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ struct vector_private {
129129
struct vector_estats estats;
130130
struct sock_fprog *bpf;
131131

132-
char user[0];
132+
char user[];
133133
};
134134

135135
extern int build_transport_data(struct vector_private *vp);

arch/um/drivers/vector_user.c

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <netdb.h>
3030
#include <stdlib.h>
3131
#include <os.h>
32+
#include <limits.h>
3233
#include <um_malloc.h>
3334
#include "vector_user.h"
3435

@@ -42,6 +43,9 @@
4243
#define TRANS_RAW "raw"
4344
#define TRANS_RAW_LEN strlen(TRANS_RAW)
4445

46+
#define TRANS_FD "fd"
47+
#define TRANS_FD_LEN strlen(TRANS_FD)
48+
4549
#define VNET_HDR_FAIL "could not enable vnet headers on fd %d"
4650
#define TUN_GET_F_FAIL "tapraw: TUNGETFEATURES failed: %s"
4751
#define L2TPV3_BIND_FAIL "l2tpv3_open : could not bind socket err=%i"
@@ -347,6 +351,59 @@ static struct vector_fds *user_init_unix_fds(struct arglist *ifspec, int id)
347351
return NULL;
348352
}
349353

354+
static int strtofd(const char *nptr)
355+
{
356+
long fd;
357+
char *endptr;
358+
359+
if (nptr == NULL)
360+
return -1;
361+
362+
errno = 0;
363+
fd = strtol(nptr, &endptr, 10);
364+
if (nptr == endptr ||
365+
errno != 0 ||
366+
*endptr != '\0' ||
367+
fd < 0 ||
368+
fd > INT_MAX) {
369+
return -1;
370+
}
371+
return fd;
372+
}
373+
374+
static struct vector_fds *user_init_fd_fds(struct arglist *ifspec)
375+
{
376+
int fd = -1;
377+
char *fdarg = NULL;
378+
struct vector_fds *result = NULL;
379+
380+
fdarg = uml_vector_fetch_arg(ifspec, "fd");
381+
fd = strtofd(fdarg);
382+
if (fd == -1) {
383+
printk(UM_KERN_ERR "fd open: bad or missing fd argument");
384+
goto fd_cleanup;
385+
}
386+
387+
result = uml_kmalloc(sizeof(struct vector_fds), UM_GFP_KERNEL);
388+
if (result == NULL) {
389+
printk(UM_KERN_ERR "fd open: allocation failed");
390+
goto fd_cleanup;
391+
}
392+
393+
result->rx_fd = fd;
394+
result->tx_fd = fd;
395+
result->remote_addr_size = 0;
396+
result->remote_addr = NULL;
397+
return result;
398+
399+
fd_cleanup:
400+
if (fd >= 0)
401+
os_close_file(fd);
402+
if (result != NULL)
403+
kfree(result);
404+
return NULL;
405+
}
406+
350407
static struct vector_fds *user_init_raw_fds(struct arglist *ifspec)
351408
{
352409
int rxfd = -1, txfd = -1;
@@ -578,6 +635,8 @@ struct vector_fds *uml_vector_user_open(
578635
return user_init_socket_fds(parsed, ID_L2TPV3);
579636
if (strncmp(transport, TRANS_BESS, TRANS_BESS_LEN) == 0)
580637
return user_init_unix_fds(parsed, ID_BESS);
638+
if (strncmp(transport, TRANS_FD, TRANS_FD_LEN) == 0)
639+
return user_init_fd_fds(parsed);
581640
return NULL;
582641
}
583642

arch/um/drivers/vhost_user.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ struct vhost_user_config {
7878
u32 offset;
7979
u32 size;
8080
u32 flags;
81-
u8 payload[0]; /* Variable length */
81+
u8 payload[]; /* Variable length */
8282
} __packed;
8383

8484
struct vhost_user_vring_state {

arch/um/drivers/virtio_uml.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ struct virtio_uml_vq_info {
7474

7575
extern unsigned long long physmem_size, highmem;
7676

77-
#define vu_err(vu_dev, ...) dev_err(&(vu_dev)->pdev->dev, __VA_ARGS__)
77+
#define vu_err(vu_dev, ...) dev_err(&(vu_dev)->pdev->dev, ##__VA_ARGS__)
7878

7979
/* Vhost-user protocol */
8080

arch/um/os-Linux/file.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <stdio.h>
77
#include <unistd.h>
88
#include <stdlib.h>
9+
#include <string.h>
910
#include <errno.h>
1011
#include <fcntl.h>
1112
#include <signal.h>
@@ -289,7 +290,7 @@ int os_write_file(int fd, const void *buf, int len)
289290

290291
int os_sync_file(int fd)
291292
{
292-
int n = fsync(fd);
293+
int n = fdatasync(fd);
293294

294295
if (n < 0)
295296
return -errno;

0 commit comments

Comments
 (0)