Re: [libvirt] [PATCH 1/5] lib: add API to query info about logged-in users

2019-07-11 Thread Jonathon Jongsma
On Thu, 2019-07-11 at 13:42 +0200, Peter Krempa wrote:
> On Thu, Jul 11, 2019 at 12:09:23 +0100, Daniel Berrange wrote:
> > On Wed, Jul 10, 2019 at 03:07:43PM -0500, Jonathon Jongsma wrote:
> > > Add API for querying logged-in users from a domain implemented
> > > via
> > > guest agent.
> > > 
> > > Signed-off-by: Jonathon Jongsma 
> > > ---
> > >  include/libvirt/libvirt-domain.h | 18 ++
> > >  src/driver-hypervisor.h  |  6 
> > >  src/libvirt-domain.c | 62
> > > 
> > >  src/libvirt_public.syms  |  5 +++
> > >  4 files changed, 91 insertions(+)
> 
> [...]
> 
> > > +int virDomainGetGuestUsers(virDomainPtr domain,
> > > +   virDomainUserInfoPtr **info,
> > > +   unsigned int flags);
> > 
> > I can easily imagine QEMU returning more info per user in future,
> > so
> > using a struct is not futureproof design.
> > 
> > We should use the virTypedParameter approach instead here.
> 
> In addition to that, once we go with typed parameters, we can make
> the
> API more universal similarly to virDomainListGetStats. Working on one
> VM only in this case, but returning all the possible queryable stuff
> from the guest agent, so that we don't have to add APIs for every
> single
> thing an user would want to query.


Good points, thanks for the feedback. 

I'll have to think a bit more about a single API for aggregated stats.
I think that could get a bit ugly, but we'll see. Are you suggesting
folding the existing agent queries (e.g. fsinfo, vcpuinfo, etc) into
this same aggregated API? 

Jonathon

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 1/5] lib: add API to query info about logged-in users

2019-07-11 Thread Peter Krempa
On Thu, Jul 11, 2019 at 12:09:23 +0100, Daniel Berrange wrote:
> On Wed, Jul 10, 2019 at 03:07:43PM -0500, Jonathon Jongsma wrote:
> > Add API for querying logged-in users from a domain implemented via
> > guest agent.
> > 
> > Signed-off-by: Jonathon Jongsma 
> > ---
> >  include/libvirt/libvirt-domain.h | 18 ++
> >  src/driver-hypervisor.h  |  6 
> >  src/libvirt-domain.c | 62 
> >  src/libvirt_public.syms  |  5 +++
> >  4 files changed, 91 insertions(+)

[...]

> > +int virDomainGetGuestUsers(virDomainPtr domain,
> > +   virDomainUserInfoPtr **info,
> > +   unsigned int flags);
> 
> I can easily imagine QEMU returning more info per user in future, so
> using a struct is not futureproof design.
> 
> We should use the virTypedParameter approach instead here.

In addition to that, once we go with typed parameters, we can make the
API more universal similarly to virDomainListGetStats. Working on one
VM only in this case, but returning all the possible queryable stuff
from the guest agent, so that we don't have to add APIs for every single
thing an user would want to query.


signature.asc
Description: PGP signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 1/5] lib: add API to query info about logged-in users

2019-07-11 Thread Daniel P . Berrangé
On Wed, Jul 10, 2019 at 03:07:43PM -0500, Jonathon Jongsma wrote:
> Add API for querying logged-in users from a domain implemented via
> guest agent.
> 
> Signed-off-by: Jonathon Jongsma 
> ---
>  include/libvirt/libvirt-domain.h | 18 ++
>  src/driver-hypervisor.h  |  6 
>  src/libvirt-domain.c | 62 
>  src/libvirt_public.syms  |  5 +++
>  4 files changed, 91 insertions(+)
> 
> diff --git a/include/libvirt/libvirt-domain.h 
> b/include/libvirt/libvirt-domain.h
> index 2dbd74d4f3..82dbbd3fc5 100644
> --- a/include/libvirt/libvirt-domain.h
> +++ b/include/libvirt/libvirt-domain.h
> @@ -4896,4 +4896,22 @@ int virDomainGetLaunchSecurityInfo(virDomainPtr domain,
> int *nparams,
> unsigned int flags);
>  
> +/**
> + * virDomainUserInfo:
> + *
> + * The data structure containing informationa bout logged-in users within a
> + * guest
> + */
> +typedef struct _virDomainUserInfo virDomainUserInfo;
> +typedef virDomainUserInfo *virDomainUserInfoPtr;
> +struct _virDomainUserInfo {
> +char *user; /* username */
> +char *domain; /* login domain (windows only) */
> +unsigned long long loginTime; /* timestamp of login for this user in ms 
> since epoch */
> +};
> +int virDomainGetGuestUsers(virDomainPtr domain,
> +   virDomainUserInfoPtr **info,
> +   unsigned int flags);

I can easily imagine QEMU returning more info per user in future, so
using a struct is not futureproof design.

We should use the virTypedParameter approach instead here.


Regards,
Daniel
-- 
|: https://berrange.com  -o-https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o-https://fstop138.berrange.com :|
|: https://entangle-photo.org-o-https://www.instagram.com/dberrange :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 1/5] lib: add API to query info about logged-in users

2019-07-10 Thread Jonathon Jongsma
Add API for querying logged-in users from a domain implemented via
guest agent.

Signed-off-by: Jonathon Jongsma 
---
 include/libvirt/libvirt-domain.h | 18 ++
 src/driver-hypervisor.h  |  6 
 src/libvirt-domain.c | 62 
 src/libvirt_public.syms  |  5 +++
 4 files changed, 91 insertions(+)

diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index 2dbd74d4f3..82dbbd3fc5 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -4896,4 +4896,22 @@ int virDomainGetLaunchSecurityInfo(virDomainPtr domain,
int *nparams,
unsigned int flags);
 
+/**
+ * virDomainUserInfo:
+ *
+ * The data structure containing informationa bout logged-in users within a
+ * guest
+ */
+typedef struct _virDomainUserInfo virDomainUserInfo;
+typedef virDomainUserInfo *virDomainUserInfoPtr;
+struct _virDomainUserInfo {
+char *user; /* username */
+char *domain; /* login domain (windows only) */
+unsigned long long loginTime; /* timestamp of login for this user in ms 
since epoch */
+};
+int virDomainGetGuestUsers(virDomainPtr domain,
+   virDomainUserInfoPtr **info,
+   unsigned int flags);
+void virDomainUserInfoFree(virDomainUserInfoPtr info);
+
 #endif /* LIBVIRT_DOMAIN_H */
diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h
index b15aaa36bc..0ef7257ace 100644
--- a/src/driver-hypervisor.h
+++ b/src/driver-hypervisor.h
@@ -1327,6 +1327,11 @@ typedef int
 int *nparams,
 unsigned int flags);
 
+typedef int
+(*virDrvDomainGetGuestUsers)(virDomainPtr domain,
+ virDomainUserInfoPtr **info,
+ unsigned int flags);
+
 
 typedef struct _virHypervisorDriver virHypervisorDriver;
 typedef virHypervisorDriver *virHypervisorDriverPtr;
@@ -1579,4 +1584,5 @@ struct _virHypervisorDriver {
 virDrvConnectBaselineHypervisorCPU connectBaselineHypervisorCPU;
 virDrvNodeGetSEVInfo nodeGetSEVInfo;
 virDrvDomainGetLaunchSecurityInfo domainGetLaunchSecurityInfo;
+virDrvDomainGetGuestUsers domainGetGuestUsers;
 };
diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index 3d12e7c125..80faa08758 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -12199,6 +12199,68 @@ virDomainSetVcpu(virDomainPtr domain,
 return -1;
 }
 
+/**
+ * virDomainGetGuestUsers:
+ * @domain: pointer to domain object
+ * @info: a pointer to a variable to store an array of user info
+ * @flags: currently unused, callers shall pass 0
+ *
+ * Queries the guest agent for the list of currently active users on the
+ * guest. The reported data depends on the guest agent implementation.
+ *
+ * This API requires the VM to run. The caller is responsible for calling
+ * virTypedParamsFree to free memory returned in @params.
+ *
+ * Returns the number of returned users, or -1 in case of error.
+ * On success, the array of the information is stored into @info. The caller is
+ * responsible for calling virDomainUserInfoFree() on each array element, then
+ * calling free() on @info. On error, @info is set to NULL.
+ */
+int
+virDomainGetGuestUsers(virDomainPtr domain,
+   virDomainUserInfoPtr **info,
+   unsigned int flags)
+{
+virResetLastError();
+
+virCheckDomainReturn(domain, -1);
+virCheckReadOnlyGoto(domain->conn->flags, error);
+
+virCheckNonNullArgGoto(info, error);
+
+if (domain->conn->driver->domainGetGuestUsers) {
+int ret;
+ret = domain->conn->driver->domainGetGuestUsers(domain, info,
+flags);
+if (ret < 0)
+goto error;
+return ret;
+}
+
+virReportUnsupportedError();
+
+ error:
+virDispatchError(domain->conn);
+return -1;
+}
+
+/**
+ * virDomainUserInfoFree:
+ * @info: pointer to a UserInfo object
+ *
+ * Frees all the memory occupied by @info.
+ */
+void
+virDomainUserInfoFree(virDomainUserInfoPtr info)
+{
+if (!info)
+return;
+
+VIR_FREE(info->user);
+VIR_FREE(info->domain);
+
+VIR_FREE(info);
+}
 
 /**
  * virDomainSetBlockThreshold:
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index 18500ec8b2..7d0e3c7849 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -836,4 +836,9 @@ LIBVIRT_5.5.0 {
 virNetworkPortSetParameters;
 } LIBVIRT_5.2.0;
 
+LIBVIRT_5.6.0 {
+global:
+virDomainGetGuestUsers;
+virDomainUserInfoFree;
+} LIBVIRT_5.5.0;
 #  define new API here using predicted next version number 
-- 
2.20.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list