e5cc85fdc4
This single function allows copying file descriptors from and to processes, and closing a previously copied remote file descriptor. This function replaces the five FD-related UDS backcalls. While it limits the total number of in-flight file descriptors to OPEN_MAX, this change greatly improves crash recovery support of UDS, since all in-flight file descriptors will be closed instead of keeping them open indefinitely (causing VFS to crash on system shutdown). With the new copyfd call, UDS becomes simpler, and the concept of filps is no longer exposed outside of VFS. This patch also moves the checkperms(2) stub into libminlib, thus fully abstracting away message details of VFS communication from UDS. Change-Id: Idd32ad390a566143c8ef66955e5ae2c221cff966
53 lines
1.1 KiB
C
53 lines
1.1 KiB
C
/* Tests for the VND driver API. Part of testvnd.sh. */
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <sys/ioctl.h>
|
|
#include <unistd.h>
|
|
#include <fcntl.h>
|
|
#include <errno.h>
|
|
|
|
/*
|
|
* For now, just test the most dreaded case: the driver being told to use the
|
|
* file descriptor used to configure the device. Without appropriate checks,
|
|
* this would cause a deadlock in VFS, since the corresponding filp object is
|
|
* locked to perform the ioctl(2) call when VFS gets the copyfd(2) back-call.
|
|
*/
|
|
int
|
|
main(int argc, char **argv)
|
|
{
|
|
struct vnd_ioctl vnd;
|
|
int fd;
|
|
|
|
if (argc != 2) {
|
|
fprintf(stderr, "usage: %s /dev/vnd0\n", argv[0]);
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
if ((fd = open(argv[1], O_RDONLY)) < 0) {
|
|
perror("open");
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
memset(&vnd, 0, sizeof(vnd));
|
|
|
|
if (ioctl(fd, VNDIOCCLR, &vnd) < 0) {
|
|
perror("ioctl(VNDIOCCLR)");
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
vnd.vnd_fildes = fd;
|
|
|
|
if (ioctl(fd, VNDIOCSET, &vnd) >= 0) {
|
|
fprintf(stderr, "ioctl(VNDIOCSET): unexpected success\n");
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
if (errno != EBADF) {
|
|
perror("ioctl(VNDIOCSET)");
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
close(fd);
|
|
|
|
return EXIT_SUCCESS;
|
|
}
|