From: David Woodhouse Date: Mon, 23 Jan 2023 16:25:02 +0000 (+0100) Subject: pass tx_id by pointer for transaction start X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=ca7c91ff279b2ef36d64903ca69019396dfc7600;p=people%2Fpauldu%2Fqemu.git pass tx_id by pointer for transaction start verify it points at XBT_NULL on the way in Signed-off-by: Paul Durrant --- diff --git a/hw/i386/kvm/trace-events b/hw/i386/kvm/trace-events index d889ef12ba..69b129a66c 100644 --- a/hw/i386/kvm/trace-events +++ b/hw/i386/kvm/trace-events @@ -8,7 +8,7 @@ xenstore_read(unsigned int tx_id, const char *path) "tx %u path %s" xenstore_write(unsigned int tx_id, const char *path) "tx %u path %s" xenstore_mkdir(unsigned int tx_id, const char *path) "tx %u path %s" xenstore_directory(unsigned int tx_id, const char *path) "tx %u path %s" -xenstore_transaction_start(unsigned int tx_id, unsigned int new_tx) "tx %u new_tx %u" +xenstore_transaction_start(unsigned int new_tx) "new_tx %u" xenstore_transaction_end(unsigned int tx_id, bool commit) "tx %u commit %d" xenstore_rm(unsigned int tx_id, const char *path) "tx %u path %s" xenstore_get_perms(unsigned int tx_id, const char *path) "tx %u path %s" diff --git a/hw/i386/kvm/xen_xenstore.c b/hw/i386/kvm/xen_xenstore.c index c9f2e01adf..27b97f4944 100644 --- a/hw/i386/kvm/xen_xenstore.c +++ b/hw/i386/kvm/xen_xenstore.c @@ -528,7 +528,6 @@ static void xs_transaction_start(XenXenstoreState *s, unsigned int req_id, { struct xsd_sockmsg *rsp = (struct xsd_sockmsg *)s->rsp_data; char *rsp_data = (char *)&rsp[1]; - unsigned int new_tx = 0; int err; if (len != 1 || req_data[0] != '\0') { @@ -541,13 +540,14 @@ static void xs_transaction_start(XenXenstoreState *s, unsigned int req_id, rsp->tx_id = tx_id; rsp->len = 0; - err = xs_impl_transaction_start(s->impl, xen_domid, tx_id, &new_tx); - trace_xenstore_transaction_start(tx_id, new_tx); + err = xs_impl_transaction_start(s->impl, xen_domid, &tx_id); if (err) { xs_error(s, req_id, tx_id, err); return; } + trace_xenstore_transaction_start(tx_id); + rsp->len = snprintf(rsp_data, XENSTORE_PAYLOAD_MAX, "%u", tx_id); assert(rsp->len < XENSTORE_PAYLOAD_MAX); rsp->len++; @@ -1390,7 +1390,7 @@ static void xs_be_unwatch(struct qemu_xs_handle *h, struct qemu_xs_watch *w) static xs_transaction_t xs_be_transaction_start(struct qemu_xs_handle *h) { unsigned int new_tx = XBT_NULL; - int err = xs_impl_transaction_start(h->impl, DOMID_QEMU, XBT_NULL, &new_tx); + int err = xs_impl_transaction_start(h->impl, DOMID_QEMU, &new_tx); if (err) { errno = err; return XBT_NULL; diff --git a/hw/i386/kvm/xenstore_impl.c b/hw/i386/kvm/xenstore_impl.c index 0039d1e345..1d614c8794 100644 --- a/hw/i386/kvm/xenstore_impl.c +++ b/hw/i386/kvm/xenstore_impl.c @@ -637,9 +637,14 @@ int xs_impl_directory(XenstoreImplState *s, unsigned int dom_id, } int xs_impl_transaction_start(XenstoreImplState *s, unsigned int dom_id, - unsigned int tx_id, unsigned int *new_tx) + unsigned int *tx_id) { - XsTransaction *tx = g_new0(XsTransaction, 1); + XsTransaction *tx; + + if (*tx_id != XBT_NULL) + return EINVAL; + + tx = g_new0(XsTransaction, 1); tx->tx_id = ++s->last_tx; tx->base_tx = s->root_tx; @@ -647,7 +652,7 @@ int xs_impl_transaction_start(XenstoreImplState *s, unsigned int dom_id, tx->dom_id = dom_id; g_hash_table_insert(s->transactions, GINT_TO_POINTER(tx->tx_id), tx); - *new_tx = tx->tx_id; + *tx_id = tx->tx_id; return 0; } diff --git a/hw/i386/kvm/xenstore_impl.h b/hw/i386/kvm/xenstore_impl.h index 44aac53216..ae3da65459 100644 --- a/hw/i386/kvm/xenstore_impl.h +++ b/hw/i386/kvm/xenstore_impl.h @@ -34,7 +34,7 @@ int xs_impl_write(XenstoreImplState *s, unsigned int dom_id, int xs_impl_directory(XenstoreImplState *s, unsigned int dom_id, unsigned int tx_id, const char *path, GList **items); int xs_impl_transaction_start(XenstoreImplState *s, unsigned int dom_id, - unsigned int tx_id, unsigned int *new_tx); + unsigned int *tx_id); int xs_impl_transaction_end(XenstoreImplState *s, unsigned int dom_id, unsigned int tx_id, bool commit); int xs_impl_rm(XenstoreImplState *s, unsigned int dom_id, unsigned int tx_id, diff --git a/tests/unit/test-xs-node.c b/tests/unit/test-xs-node.c index 782694687e..8a8aeb2020 100644 --- a/tests/unit/test-xs-node.c +++ b/tests/unit/test-xs-node.c @@ -211,7 +211,7 @@ static void do_test_xs_node_tx(bool fail, bool commit) XenstoreImplState *s = xs_impl_create(); GString *watches = g_string_new(NULL); GByteArray *data = g_byte_array_new(); - unsigned int tx_id; + unsigned int tx_id = XBT_NULL; int err; g_assert(s); @@ -230,7 +230,7 @@ static void do_test_xs_node_tx(bool fail, bool commit) g_string_truncate(watches, 0); /* Create a transaction */ - err = xs_impl_transaction_start(s, DOMID_GUEST, XBT_NULL, &tx_id); + err = xs_impl_transaction_start(s, DOMID_GUEST, &tx_id); g_assert(!err); if (fail) { @@ -308,7 +308,7 @@ static void test_xs_node_tx_rm(void) XenstoreImplState *s = xs_impl_create(); GString *watches = g_string_new(NULL); GByteArray *data = g_byte_array_new(); - unsigned int tx_id; + unsigned int tx_id = XBT_NULL; int err; g_assert(s); @@ -327,7 +327,7 @@ static void test_xs_node_tx_rm(void) g_string_truncate(watches, 0); /* Create a transaction */ - err = xs_impl_transaction_start(s, DOMID_GUEST, XBT_NULL, &tx_id); + err = xs_impl_transaction_start(s, DOMID_GUEST, &tx_id); g_assert(!err); /* Delete the tree in the transaction */ @@ -368,7 +368,7 @@ static void test_xs_node_tx_resurrect(void) XenstoreImplState *s = xs_impl_create(); GString *watches = g_string_new(NULL); GByteArray *data = g_byte_array_new(); - unsigned int tx_id; + unsigned int tx_id = XBT_NULL; int err; g_assert(s); @@ -389,7 +389,7 @@ static void test_xs_node_tx_resurrect(void) g_assert(!err); /* Create a transaction */ - err = xs_impl_transaction_start(s, DOMID_GUEST, XBT_NULL, &tx_id); + err = xs_impl_transaction_start(s, DOMID_GUEST, &tx_id); g_assert(!err); /* Delete the tree in the transaction */