And register the program, finally. Although, only stub implementation of the Remember() and Recall() functions is added. The real implementation will follow. Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- src/locking/lock_daemon.c | 37 ++++++++++++++++++ src/locking/lock_daemon.h | 8 ++++ src/locking/lock_daemon_dispatch.c | 77 ++++++++++++++++++++++++++++++++++++++ src/locking/lock_daemon_dispatch.h | 3 ++ 4 files changed, 125 insertions(+) diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c index 02d77e3..b39a63a 100644 --- a/src/locking/lock_daemon.c +++ b/src/locking/lock_daemon.c @@ -49,6 +49,7 @@ #include "locking/lock_daemon_dispatch.h" #include "locking/lock_protocol.h" +#include "locking/lock_seclabel_protocol.h" #include "configmake.h" @@ -277,6 +278,28 @@ virLockSpacePtr virLockDaemonFindLockSpace(virLockDaemonPtr lockd, } +int +virLockDaemonRememberSeclabel(virLockDaemonPtr lockd ATTRIBUTE_UNUSED, + const char *path ATTRIBUTE_UNUSED, + const char *model ATTRIBUTE_UNUSED, + const char *seclabel ATTRIBUTE_UNUSED) +{ + /* Implement me */ + return -1; +} + + +int +virLockDaemonRecallSeclabel(virLockDaemonPtr lockd ATTRIBUTE_UNUSED, + const char *path ATTRIBUTE_UNUSED, + const char *model ATTRIBUTE_UNUSED, + char **seclabel ATTRIBUTE_UNUSED) +{ + /* Implement me */ + return -1; +} + + static int virLockDaemonForkIntoBackground(const char *argv0) { @@ -1150,6 +1173,7 @@ virLockDaemonUsage(const char *argv0, bool privileged) #define MAX_LISTEN 5 int main(int argc, char **argv) { virNetServerProgramPtr lockProgram = NULL; + virNetServerProgramPtr seclabelProgram = NULL; char *remote_config_file = NULL; int statuswrite = -1; int ret = 1; @@ -1407,6 +1431,18 @@ int main(int argc, char **argv) { goto cleanup; } + if (!(seclabelProgram = virNetServerProgramNew(VIR_LOCK_SECLABEL_PROTOCOL_PROGRAM, + VIR_LOCK_SECLABEL_PROTOCOL_PROGRAM_VERSION, + virLockSeclabelProtocolProcs, + virLockSeclabelProtocolNProcs))) { + ret = VIR_LOCK_DAEMON_ERR_INIT; + goto cleanup; + } + if (virNetServerAddProgram(lockDaemon->srv, seclabelProgram) < 0) { + ret = VIR_LOCK_DAEMON_ERR_INIT; + goto cleanup; + } + /* Disable error func, now logging is setup */ virSetErrorFunc(NULL, virLockDaemonErrorHandler); @@ -1438,6 +1474,7 @@ int main(int argc, char **argv) { cleanup: virObjectUnref(lockProgram); + virObjectUnref(seclabelProgram); virLockDaemonFree(lockDaemon); if (statuswrite != -1) { if (ret != 0) { diff --git a/src/locking/lock_daemon.h b/src/locking/lock_daemon.h index da62edc..84c1fa3 100644 --- a/src/locking/lock_daemon.h +++ b/src/locking/lock_daemon.h @@ -53,4 +53,12 @@ int virLockDaemonAddLockSpace(virLockDaemonPtr lockd, virLockSpacePtr virLockDaemonFindLockSpace(virLockDaemonPtr lockd, const char *path); +int virLockDaemonRememberSeclabel(virLockDaemonPtr lockd, + const char *path, + const char *model, + const char *seclabel); +int virLockDaemonRecallSeclabel(virLockDaemonPtr lockd, + const char *path, + const char *model, + char **seclabel); #endif /* __VIR_LOCK_DAEMON_H__ */ diff --git a/src/locking/lock_daemon_dispatch.c b/src/locking/lock_daemon_dispatch.c index 168a6af..28483f4 100644 --- a/src/locking/lock_daemon_dispatch.c +++ b/src/locking/lock_daemon_dispatch.c @@ -28,6 +28,7 @@ #include "virstring.h" #include "lock_daemon.h" #include "lock_protocol.h" +#include "lock_seclabel_protocol.h" #include "virerror.h" #define VIR_FROM_THIS VIR_FROM_RPC @@ -35,6 +36,7 @@ VIR_LOG_INIT("locking.lock_daemon_dispatch"); #include "lock_daemon_dispatch_stubs.h" +#include "lock_daemon_seclabel_dispatch_stubs.h" static int virLockSpaceProtocolDispatchAcquireResource(virNetServerPtr server ATTRIBUTE_UNUSED, @@ -429,3 +431,78 @@ virLockSpaceProtocolDispatchCreateLockSpace(virNetServerPtr server ATTRIBUTE_UNU virMutexUnlock(&priv->lock); return rv; } + + +static int +virLockSeclabelProtocolDispatchRememberSeclabel(virNetServerPtr server ATTRIBUTE_UNUSED, + virNetServerClientPtr client, + virNetMessagePtr msg ATTRIBUTE_UNUSED, + virNetMessageErrorPtr rerr, + virLockSeclabelProtocolRememberSeclabelArgs *args, + virLockSeclabelProtocolRememberSeclabelRet *ret) +{ + int rc = -1; + int rv; + virLockDaemonClientPtr priv = + virNetServerClientGetPrivateData(client); + + virMutexLock(&priv->lock); + + if (priv->restricted) { + virReportError(VIR_ERR_OPERATION_DENIED, "%s", + _("lock manager connection has been restricted")); + goto cleanup; + } + + if ((rv = virLockDaemonRememberSeclabel(lockDaemon, args->path, + args->model, args->seclabel)) < 0) + goto cleanup; + + ret->ret = rv; + rc = 0; + + cleanup: + if (rc < 0) + virNetMessageSaveError(rerr); + virMutexUnlock(&priv->lock); + return rc; +} + + +static int +virLockSeclabelProtocolDispatchRecallSeclabel(virNetServerPtr server ATTRIBUTE_UNUSED, + virNetServerClientPtr client, + virNetMessagePtr msg ATTRIBUTE_UNUSED, + virNetMessageErrorPtr rerr, + virLockSeclabelProtocolRecallSeclabelArgs *args, + virLockSeclabelProtocolRecallSeclabelRet *ret) +{ + int rc = -1; + int rv; + virLockDaemonClientPtr priv = + virNetServerClientGetPrivateData(client); + char *seclabel = NULL; + + virMutexLock(&priv->lock); + + if (priv->restricted) { + virReportError(VIR_ERR_OPERATION_DENIED, "%s", + _("lock manager connection has been restricted")); + goto cleanup; + } + + if ((rv = virLockDaemonRecallSeclabel(lockDaemon, args->path, + args->model, &seclabel)) < 0) + goto cleanup; + + ret->seclabel = seclabel; + ret->ret = rv; + + rc = 0; + + cleanup: + if (rc < 0) + virNetMessageSaveError(rerr); + virMutexUnlock(&priv->lock); + return rc; +} diff --git a/src/locking/lock_daemon_dispatch.h b/src/locking/lock_daemon_dispatch.h index a193a58..e5d540b 100644 --- a/src/locking/lock_daemon_dispatch.h +++ b/src/locking/lock_daemon_dispatch.h @@ -28,4 +28,7 @@ extern virNetServerProgramProc virLockSpaceProtocolProcs[]; extern size_t virLockSpaceProtocolNProcs; +extern virNetServerProgramProc virLockSeclabelProtocolProcs[]; +extern size_t virLockSeclabelProtocolNProcs; + #endif /* __VIR_LOCK_DAEMON_DISPATCH_H__ */ -- 1.8.5.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list