1 /* libxenstat: statistics-collection library for Xen
2  * Copyright (C) International Business Machines Corp., 2005
3  * Authors: Josh Triplett <josht@us.ibm.com>
4  *          Judy Fischbach <jfisch@us.ibm.com>
5  *          David Hendricks <dhendrix@us.ibm.com>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  */
17 
18 /*
19  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
20  * Use is subject to license terms.
21  */
22 
23 #include <fcntl.h>
24 #include <dirent.h>
25 #include <sys/types.h>
26 #include <sys/stat.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <unistd.h>
31 
32 #include "xenstat_priv.h"
33 
34 #define SYSFS_VBD_PATH "/sys/devices/xen-backend/"
35 
36 struct priv_data {
37 	FILE *procnetdev;
38 	DIR *sysfsvbd;
39 };
40 
41 static struct priv_data *
get_priv_data(xenstat_handle * handle)42 get_priv_data(xenstat_handle *handle)
43 {
44 	if (handle->priv != NULL)
45 		return handle->priv;
46 
47 	handle->priv = malloc(sizeof(struct priv_data));
48 	if (handle->priv == NULL)
49 		return (NULL);
50 
51 	((struct priv_data *)handle->priv)->procnetdev = NULL;
52 	((struct priv_data *)handle->priv)->sysfsvbd = NULL;
53 
54 	return handle->priv;
55 }
56 
57 /* Expected format of /proc/net/dev */
58 
59 /* Collect information about networks */
xenstat_collect_networks(xenstat_node * node)60 int xenstat_collect_networks(xenstat_node * node)
61 {
62 	/* XXX fixme: implement code to get stats from libkvm ! */
63 	return 1;
64 }
65 
66 /* Free network information in handle */
xenstat_uninit_networks(xenstat_handle * handle)67 void xenstat_uninit_networks(xenstat_handle * handle)
68 {
69 	struct priv_data *priv = get_priv_data(handle);
70 	if (priv != NULL && priv->procnetdev != NULL)
71 		fclose(priv->procnetdev);
72 }
73 
74 /* Collect information about VBDs */
xenstat_collect_vbds(xenstat_node * node)75 int xenstat_collect_vbds(xenstat_node * node)
76 {
77 	return 1;
78 }
79 
80 /* Free VBD information in handle */
xenstat_uninit_vbds(xenstat_handle * handle)81 void xenstat_uninit_vbds(xenstat_handle * handle)
82 {
83 	struct priv_data *priv = get_priv_data(handle);
84 	if (priv != NULL && priv->sysfsvbd != NULL)
85 		closedir(priv->sysfsvbd);
86 }
87