admin: Introduce virAdmServerLookupClient

Just like with server-related APIs, before any of client-based APIs can be
called, a reference to a client-side client object needs to be obtained. For
this purpose, a lookup method should exist. Apart from the client retrieval
logic, a new error code for non-existent client had to be added as well.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
Erik Skultety 2016-04-22 09:47:09 +02:00
parent 7884d089d2
commit 52a2eef948
12 changed files with 116 additions and 1 deletions

View File

@ -201,3 +201,13 @@ adminServerListClients(virNetServerPtr srv,
virObjectListFreeCount(clts, ret);
return ret;
}
virNetServerClientPtr
adminServerLookupClient(virNetServerPtr srv,
unsigned long long id,
unsigned int flags)
{
virCheckFlags(0, NULL);
return virNetServerGetClient(srv, id);
}

View File

@ -50,4 +50,8 @@ int adminServerListClients(virNetServerPtr srv,
virNetServerClientPtr **clients,
unsigned int flags);
virNetServerClientPtr adminServerLookupClient(virNetServerPtr srv,
unsigned long long id,
unsigned int flags);
#endif /* __LIBVIRTD_ADMIN_SERVER_H__ */

View File

@ -219,6 +219,11 @@ int virAdmServerListClients(virAdmServerPtr srv,
virAdmClientPtr **clients,
unsigned int flags);
virAdmClientPtr
virAdmServerLookupClient(virAdmServerPtr srv,
unsigned long long id,
unsigned int flags);
# ifdef __cplusplus
}
# endif

View File

@ -314,6 +314,7 @@ typedef enum {
VIR_ERR_MIGRATE_FINISH_OK = 93, /* Finish API succeeded but it is expected to return NULL */
VIR_ERR_AUTH_UNAVAILABLE = 94, /* authentication unavailable */
VIR_ERR_NO_SERVER = 95, /* Server was not found */
VIR_ERR_NO_CLIENT = 96, /* Client was not found */
} virErrorNumber;
/**

View File

@ -138,6 +138,16 @@ struct admin_server_list_clients_ret { /* insert@1 */
unsigned int ret;
};
struct admin_server_lookup_client_args {
admin_nonnull_server srv;
unsigned hyper id;
unsigned int flags;
};
struct admin_server_lookup_client_ret {
admin_nonnull_client clnt;
};
/* Define the program number, protocol version and procedure numbers here. */
const ADMIN_PROGRAM = 0x06900690;
const ADMIN_PROTOCOL_VERSION = 1;
@ -198,5 +208,10 @@ enum admin_procedure {
/**
* @generate: both
*/
ADMIN_PROC_SERVER_LIST_CLIENTS = 8
ADMIN_PROC_SERVER_LIST_CLIENTS = 8,
/**
* @generate: both
*/
ADMIN_PROC_SERVER_LOOKUP_CLIENT = 9
};

View File

@ -87,6 +87,14 @@ struct admin_server_list_clients_ret {
} clients;
u_int ret;
};
struct admin_server_lookup_client_args {
admin_nonnull_server srv;
uint64_t id;
u_int flags;
};
struct admin_server_lookup_client_ret {
admin_nonnull_client clnt;
};
enum admin_procedure {
ADMIN_PROC_CONNECT_OPEN = 1,
ADMIN_PROC_CONNECT_CLOSE = 2,
@ -96,4 +104,5 @@ enum admin_procedure {
ADMIN_PROC_SERVER_GET_THREADPOOL_PARAMETERS = 6,
ADMIN_PROC_SERVER_SET_THREADPOOL_PARAMETERS = 7,
ADMIN_PROC_SERVER_LIST_CLIENTS = 8,
ADMIN_PROC_SERVER_LOOKUP_CLIENT = 9,
};

View File

@ -889,3 +889,39 @@ virAdmServerListClients(virAdmServerPtr srv,
virDispatchError(NULL);
return -1;
}
/**
* virAdmServerLookupClient:
* @srv: a valid server object reference
* @id: ID of the client to lookup on server @srv
* @flags: extra flags; not used yet, so callers should always pass 0
*
* Try to lookup a client on the given server based on @id.
*
* virAdmClientFree() should be used to free the resources after the
* client object is no longer needed.
*
* Returns the requested client or NULL in case of failure. If the
* client could not be found, then VIR_ERR_NO_CLIENT error is raised.
*/
virAdmClientPtr
virAdmServerLookupClient(virAdmServerPtr srv,
unsigned long long id,
unsigned int flags)
{
virAdmClientPtr ret = NULL;
VIR_DEBUG("srv=%p, id=%llu, flags=%x", srv, id, flags);
virResetLastError();
virCheckAdmServerGoto(srv, error);
virCheckFlagsGoto(0, error);
if (!(ret = remoteAdminServerLookupClient(srv, id, flags)))
goto error;
return ret;
error:
virDispatchError(NULL);
return NULL;
}

View File

@ -16,6 +16,8 @@ xdr_admin_server_get_threadpool_parameters_args;
xdr_admin_server_get_threadpool_parameters_ret;
xdr_admin_server_list_clients_args;
xdr_admin_server_list_clients_ret;
xdr_admin_server_lookup_client_args;
xdr_admin_server_lookup_client_ret;
xdr_admin_server_set_threadpool_parameters_args;
# datatypes.h

View File

@ -29,6 +29,7 @@ LIBVIRT_ADMIN_1.3.0 {
virAdmServerGetName;
virAdmServerGetThreadPoolParameters;
virAdmServerFree;
virAdmServerLookupClient;
virAdmConnectLookupServer;
virAdmServerSetThreadPoolParameters;
virAdmServerListClients;

View File

@ -972,3 +972,26 @@ virNetServerGetClients(virNetServerPtr srv,
virObjectUnlock(srv);
return ret;
}
virNetServerClientPtr
virNetServerGetClient(virNetServerPtr srv,
unsigned long long id)
{
size_t i;
virNetServerClientPtr ret = NULL;
virObjectLock(srv);
for (i = 0; i < srv->nclients; i++) {
virNetServerClientPtr client = srv->clients[i];
if (virNetServerClientGetID(client) == id)
ret = virObjectRef(client);
}
virObjectUnlock(srv);
if (!ret)
virReportError(VIR_ERR_NO_CLIENT,
_("No client with matching ID '%llu'"), id);
return ret;
}

View File

@ -105,6 +105,9 @@ int virNetServerSetThreadPoolParameters(virNetServerPtr srv,
unsigned long long virNetServerNextClientID(virNetServerPtr srv);
virNetServerClientPtr virNetServerGetClient(virNetServerPtr srv,
unsigned long long id);
int virNetServerGetClients(virNetServerPtr srv,
virNetServerClientPtr **clients);

View File

@ -1388,6 +1388,12 @@ virErrorMsg(virErrorNumber error, const char *info)
else
errmsg = _("Server not found: %s");
break;
case VIR_ERR_NO_CLIENT:
if (info == NULL)
errmsg = _("Client not found");
else
errmsg = _("Client not found: %s");
break;
}
return errmsg;
}