@@ -22,6 +22,7 @@ Interactive commands for Xen Store Daemon.
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
+#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
@@ -307,7 +308,24 @@ static const char *lu_arch(const void *ctx, struct connection *conn,
static const char *lu_check_lu_allowed(const void *ctx, bool force,
unsigned int to)
{
- return NULL;
+ char *ret = NULL;
+ struct connection *conn;
+ time_t now = time(NULL);
+ bool busy = false;
+
+ list_for_each_entry(conn, &connections, list) {
+ if (conn->ta_start_time - now >= to && !force) {
+ ret = talloc_asprintf(ctx, "%s\nDomain %u: %ld s",
+ ret ? : "Domains with long running transactions:",
+ conn->id,
+ conn->ta_start_time - now);
+ if (!ret)
+ busy = true;
+ } else if (conn->ta_start_time)
+ busy = true;
+ }
+
+ return ret ? (const char *)ret : (busy ? "BUSY" : NULL);
}
static const char *lu_dump_state(const void *ctx, struct connection *conn)
@@ -93,6 +93,7 @@ struct connection
struct list_head transaction_list;
uint32_t next_transaction_id;
unsigned int transaction_started;
+ time_t ta_start_time;
/* The domain I'm associated with, if any. */
struct domain *domain;
@@ -473,6 +473,8 @@ int do_transaction_start(struct connection *conn, struct buffered_data *in)
list_add_tail(&trans->list, &conn->transaction_list);
talloc_steal(conn, trans);
talloc_set_destructor(trans, destroy_transaction);
+ if (!conn->transaction_started)
+ conn->ta_start_time = time(NULL);
conn->transaction_started++;
wrl_ntransactions++;
@@ -511,6 +513,8 @@ int do_transaction_end(struct connection *conn, struct buffered_data *in)
conn->transaction = NULL;
list_del(&trans->list);
conn->transaction_started--;
+ if (!conn->transaction_started)
+ conn->ta_start_time = 0;
/* Attach transaction to in for auto-cleanup */
talloc_steal(in, trans);
@@ -589,6 +593,7 @@ void conn_delete_all_transactions(struct connection *conn)
assert(conn->transaction == NULL);
conn->transaction_started = 0;
+ conn->ta_start_time = 0;
}
int check_transactions(struct hashtable *hash)