Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/locking/lock_daemon.c | 44 ++++++++++++++++++++++++++
src/locking/lock_daemon.h | 8 +++++
src/locking/lock_daemon_dispatch.c | 65 ++++++++++++++++++++++++++++++++------
3 files changed, 108 insertions(+), 9 deletions(-)
diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c
index 3984b4d..3a0a7ff 100644
--- a/src/locking/lock_daemon.c
+++ b/src/locking/lock_daemon.c
@@ -49,6 +49,7 @@
#include "virstring.h"
#include "locking/lock_daemon_dispatch.h"
+#include "locking/lock_daemon_seclabels.h"
#include "locking/lock_protocol.h"
#include "configmake.h"
@@ -64,6 +65,7 @@ struct _virLockDaemon {
virNetDaemonPtr dmn;
virHashTablePtr lockspaces;
virLockSpacePtr defaultLockspace;
+ virSeclabelSpacePtr seclabelSpace;
};
virLockDaemonPtr lockDaemon = NULL;
@@ -121,6 +123,7 @@ virLockDaemonFree(virLockDaemonPtr lockd)
virObjectUnref(lockd->dmn);
virHashFree(lockd->lockspaces);
virLockSpaceFree(lockd->defaultLockspace);
+ virSeclabelSpaceFree(lockd->seclabelSpace);
VIR_FREE(lockd);
}
@@ -179,6 +182,9 @@ virLockDaemonNew(virLockDaemonConfigPtr config, bool privileged)
if (!(lockd->defaultLockspace = virLockSpaceNew(NULL)))
goto error;
+ if (!(lockd->seclabelSpace = virSeclabelSpaceNew()))
+ goto error;
+
return lockd;
error:
@@ -193,6 +199,7 @@ virLockDaemonNewPostExecRestart(virJSONValuePtr object, bool
privileged)
virLockDaemonPtr lockd;
virJSONValuePtr child;
virJSONValuePtr lockspaces;
+ virJSONValuePtr seclabelSpace;
virNetServerPtr srv;
size_t i;
ssize_t n;
@@ -248,6 +255,14 @@ virLockDaemonNewPostExecRestart(virJSONValuePtr object, bool
privileged)
}
}
+ if (!(seclabelSpace = virJSONValueObjectGet(object, "seclabelSpace"))) {
+ /* It's okay, if there's not seclabel space info. */
+ if (!(lockd->seclabelSpace = virSeclabelSpaceNew()))
+ goto error;
+ } else if (!(lockd->seclabelSpace =
virSeclabelSpacePostExecRestart(seclabelSpace))) {
+ goto error;
+ }
+
if (virJSONValueObjectHasKey(object, "daemon")) {
if (!(child = virJSONValueObjectGet(object, "daemon"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -281,6 +296,26 @@ virLockDaemonNewPostExecRestart(virJSONValuePtr object, bool
privileged)
}
+int virLockDaemonRememberSeclabel(virLockDaemonPtr lockd,
+ const char *path,
+ const char *model,
+ const char *label)
+{
+ return virSeclabelSpaceRemember(lockd->seclabelSpace,
+ path, model, label);
+}
+
+
+int virLockDaemonRecallSeclabel(virLockDaemonPtr lockd,
+ const char *path,
+ const char *model,
+ char **label)
+{
+ return virSeclabelSpaceRecall(lockd->seclabelSpace,
+ path, model, label);
+}
+
+
int virLockDaemonAddLockSpace(virLockDaemonPtr lockd,
const char *path,
virLockSpacePtr lockspace)
@@ -1005,6 +1040,7 @@ virLockDaemonPreExecRestart(const char *state_file,
char *magic;
virHashKeyValuePairPtr pairs = NULL, tmp;
virJSONValuePtr lockspaces;
+ virJSONValuePtr seclabelSpace;
VIR_DEBUG("Running pre-restart exec");
@@ -1050,6 +1086,14 @@ virLockDaemonPreExecRestart(const char *state_file,
tmp++;
}
+ if (!(seclabelSpace = virSeclabelSpacePreExecRestart(lockDaemon->seclabelSpace)))
+ goto cleanup;
+
+ if (virJSONValueObjectAppend(object, "seclabelSpace", seclabelSpace) <
0) {
+ virJSONValueFree(seclabelSpace);
+ goto cleanup;
+ }
+
if (!(magic = virLockDaemonGetExecRestartMagic()))
goto cleanup;
diff --git a/src/locking/lock_daemon.h b/src/locking/lock_daemon.h
index da62edc..fb72a73 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 *label);
+int virLockDaemonRecallSeclabel(virLockDaemonPtr lockd,
+ const char *path,
+ const char *model,
+ char **label);
#endif /* __VIR_LOCK_DAEMON_H__ */
diff --git a/src/locking/lock_daemon_dispatch.c b/src/locking/lock_daemon_dispatch.c
index 2d0bd81..5ad7e11 100644
--- a/src/locking/lock_daemon_dispatch.c
+++ b/src/locking/lock_daemon_dispatch.c
@@ -24,6 +24,7 @@
#include "rpc/virnetdaemon.h"
#include "rpc/virnetserverclient.h"
+#include "viralloc.h"
#include "virlog.h"
#include "virstring.h"
#include "lock_daemon.h"
@@ -36,6 +37,7 @@
VIR_LOG_INIT("locking.lock_daemon_dispatch");
#include "lock_daemon_dispatch_stubs.h"
+#include "lock_daemon_seclabels.h"
static int
virLockSpaceProtocolDispatchAcquireResource(virNetServerPtr server ATTRIBUTE_UNUSED,
@@ -433,21 +435,66 @@ virLockSpaceProtocolDispatchCreateLockSpace(virNetServerPtr server
ATTRIBUTE_UNU
static int
virLockSpaceProtocolDispatchRememberSeclabel(virNetServerPtr server ATTRIBUTE_UNUSED,
- virNetServerClientPtr client
ATTRIBUTE_UNUSED,
+ virNetServerClientPtr client,
virNetMessagePtr msg ATTRIBUTE_UNUSED,
- virNetMessageErrorPtr rerr
ATTRIBUTE_UNUSED,
- virLockSpaceProtocolRememberSeclabelArgs
*args ATTRIBUTE_UNUSED)
+ virNetMessageErrorPtr rerr,
+ virLockSpaceProtocolRememberSeclabelArgs
*args)
{
- return 0;
+ int rv = -1;
+ virLockDaemonClientPtr priv =
+ virNetServerClientGetPrivateData(client);
+
+ virMutexLock(&priv->lock);
+
+ if (virLockDaemonRememberSeclabel(lockDaemon,
+ args->path, args->model, args->label) <
0)
+ goto cleanup;
+
+ rv = 0;
+ cleanup:
+ if (rv < 0)
+ virNetMessageSaveError(rerr);
+ virMutexUnlock(&priv->lock);
+ return rv;
}
static int
virLockSpaceProtocolDispatchRecallSeclabel(virNetServerPtr server ATTRIBUTE_UNUSED,
- virNetServerClientPtr client
ATTRIBUTE_UNUSED,
+ virNetServerClientPtr client,
virNetMessagePtr msg ATTRIBUTE_UNUSED,
- virNetMessageErrorPtr rerr ATTRIBUTE_UNUSED,
- virLockSpaceProtocolRecallSeclabelArgs *args
ATTRIBUTE_UNUSED,
- virLockSpaceProtocolRecallSeclabelRet *ret
ATTRIBUTE_UNUSED)
+ virNetMessageErrorPtr rerr,
+ virLockSpaceProtocolRecallSeclabelArgs *args,
+ virLockSpaceProtocolRecallSeclabelRet *ret)
{
- return 0;
+ int rv = -1;
+ int funcRet;
+ virLockDaemonClientPtr priv =
+ virNetServerClientGetPrivateData(client);
+ char *label = NULL;
+ char **label_p = NULL;
+
+ virMutexLock(&priv->lock);
+
+ memset(ret, 0, sizeof(*ret));
+
+ funcRet = virLockDaemonRecallSeclabel(lockDaemon,
+ args->path, args->model, &label);
+
+ if (funcRet == 0 &&
+ (VIR_ALLOC(label_p) < 0 ||
+ VIR_STRDUP(*label_p, label) < 0))
+ goto cleanup;
+
+ ret->label = label_p;
+ ret->ret = funcRet;
+ rv = 0;
+
+ cleanup:
+ if (rv < 0) {
+ VIR_FREE(label_p);
+ virNetMessageSaveError(rerr);
+ }
+ virMutexUnlock(&priv->lock);
+ VIR_FREE(label);
+ return rv;
}
--
2.4.9