virtiofsd unix socket

https://www.cnblogs.com/yi-mu-xi/p/12923523.html

 

 vhost_user_backend_init()

---------........

---------vhost_setup_slave_channel(dev)

------------------.........

------------------qemu_set_fd_handler(u->slave_fd, slave_read, NULL, dev)

------------------.......

 

 

 

 

vhost_setup_slave_channel

 

 

 

//hw/virtio/vhost-user.c中
slave_read()
{
......
#ifdef CONFIG_VHOST_USER_FS
    case VHOST_USER_SLAVE_FS_MAP:
        ret = vhost_user_fs_slave_map(dev, &payload.fs, fd[0]);
        break;
    case VHOST_USER_SLAVE_FS_UNMAP:
        ret = vhost_user_fs_slave_unmap(dev, &payload.fs);
        break;
    case VHOST_USER_SLAVE_FS_SYNC:
        ret = vhost_user_fs_slave_sync(dev, &payload.fs);
        break;
#endif

…….
}

 

contrib/virtiofsd/fuse_virtio.c:722:int virtio_session_mount(struct fuse_session *se)  创建服务端

721 
722 int virtio_session_mount(struct fuse_session *se)
723 {
724         struct sockaddr_un un;
725 
726         if (strlen(se->vu_socket_path) >= sizeof(un.sun_path)) {
727                 fprintf(stderr, "Socket path too long\n");
728                 return -1;
729         }
730 
731         /* Poison the fuse FD so we spot if we accidentally use it;
732          * DO NOT check for this value, check for se->vu_socket_path
733          */
734         se->fd = 0xdaff0d11;
735 
736         /* Create the Unix socket to communicate with qemu
737          * based on QEMU's vhost-user-bridge
738          */
739         unlink(se->vu_socket_path);
740         strcpy(un.sun_path, se->vu_socket_path);
741         size_t addr_len = sizeof(un.sun_family) + strlen(se->vu_socket_path);
742 
743         int listen_sock = socket(AF_UNIX, SOCK_STREAM, 0);
744         if (listen_sock == -1) {
745                perror("vhost socket creation");
746                return -1;
747         }
748         un.sun_family = AF_UNIX;
749 
750         if (bind(listen_sock, (struct sockaddr *) &un, addr_len) == -1) {
751                 perror("vhost socket bind");
752                 return -1;
753         }
754 
755         if (listen(listen_sock, 1) == -1) {
756                 perror("vhost socket listen");
757                 return -1;
758         }
759 
760         fprintf(stderr, "%s: Waiting for vhost-user socket connection...\n", __func__);
761         int data_sock = accept(listen_sock, NULL, NULL);
762         if (data_sock == -1) {
763                 perror("vhost socket accept");
764                 close(listen_sock);
765                 return -1;
766         }
767         close(listen_sock);
768         fprintf(stderr, "%s: Received vhost-user socket connection\n", __func__);
769         se->vu_socketfd = data_sock;

770 
771         /* TODO: Some cleanup/deallocation! */
772         se->virtio_dev = calloc(sizeof(struct fv_VuDev), 1);
773         se->virtio_dev->se = se;
774         vu_init(&se->virtio_dev->dev, se->vu_socketfd,
775                 fv_panic,
776                 fv_set_watch, fv_remove_watch,
777                 &fv_iface);
778 
779         return 0;
780 }

 

posted on 2020-10-24 12:53  tycoon3  阅读(234)  评论(0编辑  收藏  举报

导航