]> git.proxmox.com Git - pve-cluster.git/commitdiff
implement sendfd to support qemu fdset functionality
authorDietmar Maurer <dietmar@proxmox.com>
Wed, 5 Dec 2012 11:02:34 +0000 (12:02 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 5 Dec 2012 11:02:34 +0000 (12:02 +0100)
Makefile
data/PVE/IPCC.pm
data/PVE/IPCC.xs
debian/changelog

index 0b4534b6cedf9bf513990b4f07f4974085982ac1..de5ce4867d3afaa4a48dba200e4a2ed79a5bf51d 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@ RELEASE=2.2
 
 PACKAGE=pve-cluster
 PKGVER=1.0
-PKGREL=33
+PKGREL=34
 
 ARCH:=$(shell dpkg-architecture -qDEB_BUILD_ARCH)
 
index 28579ff90f4c877ab7baf0396e06cc03ca5b62bf..529ebf5dde4c849b62b37c0907bf003a5b48dfa3 100644 (file)
@@ -34,7 +34,6 @@ XSLoader::load('PVE::IPCC', $VERSION);
 
 1;
 __END__
-# Below is stub documentation for your module. You'd better edit it!
 
 =head1 NAME
 
@@ -46,10 +45,15 @@ PVE::IPCC - Perl extension to access the PVE IPC Server
   
   my $res = PVE::IPCC::ipcc_send_rec(1, "hello");
  
+  my $res = PVE::IPCC::sendfd($socketfd, $fd, $opt_data);
+
 =head1 DESCRIPTION
 
 Send/receive RAW data packets from the PVE IPC Server.
 
+Pass file descriptor over unix domain sockets (used to pass
+file destriptors to qemu fdset). This is use in PVE::QMPClient.
+
 =head2 EXPORT
 
 None by default.
index 3da7059b7107f0841e4076a65b93a16491232531..6c27ad5b8b8c0705ba26f731ee6575a77d697ce3 100644 (file)
@@ -8,6 +8,18 @@
 
 #include "ppport.h"
 
+/* sendfd: BSD style file descriptor passing over unix domain sockets
+ *  Richard Stevens: Unix Network Programming, Prentice Hall, 1990;
+ */
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/uio.h>
+#include <errno.h>
+
+#ifndef SCM_RIGHTS
+#error "SCM_RIGHTS undefined"
+#endif 
+
 #include <sys/syslog.h>
 #include <qb/qbdefs.h>
 #include <qb/qbutil.h>
@@ -107,3 +119,49 @@ CODE:
 }
 OUTPUT: RETVAL
 
+# helper to pass SCM ACCESS RIGHTS
+
+int
+sendfd(sock_fd, send_me_fd, data=NULL)
+int sock_fd
+int send_me_fd
+SV * data;
+CODE:
+{
+       int ret = 0;
+       struct iovec  iov[1];
+       struct msghdr msg;
+       memset(&msg, 0, sizeof(msg));
+
+       size_t len = 0;
+       char *dataptr = NULL;
+       if (data && SvPOK(data))
+               dataptr = SvPV(data, len);
+       
+       iov[0].iov_base = dataptr;
+       iov[0].iov_len = len;   
+       msg.msg_iov = iov;
+       msg.msg_iovlen = 1;
+       msg.msg_name = 0;
+       msg.msg_namelen = 0;
+
+       char control[CMSG_SPACE(sizeof(int))];
+       memset(control, 0, sizeof(control));
+
+       msg.msg_control = control;
+       msg.msg_controllen = sizeof(control);
+       msg.msg_flags = 0;
+               
+       struct cmsghdr* h = CMSG_FIRSTHDR(&msg);
+       h->cmsg_len = CMSG_LEN(sizeof(int));
+       h->cmsg_level= SOL_SOCKET;
+       h->cmsg_type = SCM_RIGHTS;
+       *((int*)CMSG_DATA(h)) = send_me_fd;
+
+       do {
+               ret = sendmsg(sock_fd, &msg, 0);
+       } while (ret < 0 && errno == EINTR);
+
+       RETVAL = ret;
+}
+OUTPUT: RETVAL
index 548c45cb690dcf59e10c51747a69e0e339f7a01f..4cf4f8dc4fbe32258e4c3358c8852e2730cbd869 100644 (file)
@@ -1,3 +1,9 @@
+pve-cluster (1.0-34) unstable; urgency=low
+
+  * implement sendfd to support qemu fdset functionality.
+
+ -- Proxmox Support Team <support@proxmox.com>  Wed, 05 Dec 2012 12:02:09 +0100
+
 pve-cluster (1.0-33) unstable; urgency=low
 
   * import existing /root/.ssh/authorized_keys