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 static const char PROCNETDEV_HEADER[] =
59     "Inter-|   Receive                                                |"
60     "  Transmit\n"
61     " face |bytes    packets errs drop fifo frame compressed multicast|"
62     "bytes    packets errs drop fifo colls carrier compressed\n";
63 
64 /* Collect information about networks */
xenstat_collect_networks(xenstat_node * node)65 int xenstat_collect_networks(xenstat_node * node)
66 {
67 	/* XXX fixme: implement code to get stats from libkvm ! */
68 	return 1;
69 }
70 
71 /* Free network information in handle */
xenstat_uninit_networks(xenstat_handle * handle)72 void xenstat_uninit_networks(xenstat_handle * handle)
73 {
74 	struct priv_data *priv = get_priv_data(handle);
75 	if (priv != NULL && priv->procnetdev != NULL)
76 		fclose(priv->procnetdev);
77 }
78 
read_attributes_vbd(const char * vbd_directory,const char * what,char * ret,int cap)79 static int read_attributes_vbd(const char *vbd_directory, const char *what, char *ret, int cap)
80 {
81 	/* XXX implement */
82 	return 0;
83 }
84 
85 /* Collect information about VBDs */
xenstat_collect_vbds(xenstat_node * node)86 int xenstat_collect_vbds(xenstat_node * node)
87 {
88 	return 1;
89 }
90 
91 /* Free VBD information in handle */
xenstat_uninit_vbds(xenstat_handle * handle)92 void xenstat_uninit_vbds(xenstat_handle * handle)
93 {
94 	struct priv_data *priv = get_priv_data(handle);
95 	if (priv != NULL && priv->sysfsvbd != NULL)
96 		closedir(priv->sysfsvbd);
97 }
98