summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Catanzaro <mcatanzaro@gnome.org>2020-11-06 09:52:00 -0600
committerMichael Catanzaro <mcatanzaro@gnome.org>2020-11-06 09:52:00 -0600
commit30bf8d04183c26ca48c6cd4efe4c24058a082783 (patch)
treea2d4e2598e52ba8863182d76515caaed1dce65ab
parentea08151ae6582a438db76b738293a0194c964b88 (diff)
downloadlibgtop-30bf8d04183c26ca48c6cd4efe4c24058a082783.tar.gz
Revert "Handle LVM and RAID"
This reverts commit 9cbb3b91f11ad0c4944a1428d609201c054cffab.
-rw-r--r--glibtop.h2
-rw-r--r--include/glibtop/disk.h10
-rw-r--r--sysdeps/common/default.c4
-rw-r--r--sysdeps/linux/disk.c218
-rw-r--r--sysdeps/linux/glibtop_private.c27
-rw-r--r--sysdeps/linux/glibtop_private.h4
6 files changed, 36 insertions, 229 deletions
diff --git a/glibtop.h b/glibtop.h
index c196818c..804294da 100644
--- a/glibtop.h
+++ b/glibtop.h
@@ -80,7 +80,7 @@ struct _glibtop
int socket; /* Accepted connection of a socket */
int ncpu; /* Number of CPUs, zero if single-processor */
int real_ncpu; /* Real number of CPUs. Only ncpu are monitored */
- int ndisk; /* Number of DISKs, zero if single-disk */
+ int ndisk; /* Number of DISKs, zero if single-disk */
int real_ndisk; /* Number of PHYSICAL DISKs. Only ncpu is monitored */
unsigned long os_version_code; /* Version code of the operating system */
const char *name; /* Program name for error messages */
diff --git a/include/glibtop/disk.h b/include/glibtop/disk.h
index cdde7796..8843112c 100644
--- a/include/glibtop/disk.h
+++ b/include/glibtop/disk.h
@@ -42,14 +42,6 @@ G_BEGIN_DECLS
typedef struct _glibtop_disk glibtop_disk;
-struct _partition_info
-{
- char name[256];
- char type[256];
- char raid_num[256];
- int max;
-};
-
struct _glibtop_disk
{
guint64 xdisk_sectors_read [GLIBTOP_NDISK]; /* GLIBTOP_XDISK_SECTORS_READ */
@@ -58,7 +50,7 @@ struct _glibtop_disk
guint64 xdisk_time_write [GLIBTOP_NDISK]; /* GLIBTOP_XDISK_TIME_WRITE */
};
-void glibtop_get_disk (glibtop_disk *buf);
+void glibtop_get_disk(glibtop_disk *buf);
#if GLIBTOP_SUID_DISK
#define glibtop_get_disk_r glibtop_get_disk_p
diff --git a/sysdeps/common/default.c b/sysdeps/common/default.c
index 653a4f5a..c20f2938 100644
--- a/sysdeps/common/default.c
+++ b/sysdeps/common/default.c
@@ -72,9 +72,9 @@ glibtop_get_cpu(glibtop_cpu *buf)
*
*/
void
-glibtop_get_cpu (glibtop_cpu *buf)
+glibtop_get_cpu(glibtop_cpu *buf)
{
- glibtop_get_cpu_l (glibtop_global_server, buf);
+ glibtop_get_cpu_l(glibtop_global_server, buf);
}
diff --git a/sysdeps/linux/disk.c b/sysdeps/linux/disk.c
index 3ad74bcc..159f8f12 100644
--- a/sysdeps/linux/disk.c
+++ b/sysdeps/linux/disk.c
@@ -39,244 +39,58 @@ _glibtop_init_disk_s (glibtop *server)
/* Provides information about disk usage. */
-// Linux kernel reports sectors by 512 bytes even for AF 4kn //
-
-#define FILENAME "/proc/diskstats"
-#define CMD_PIPE "lsblk --output NAME,TYPE -i -n | sed 's/`-//'|sed 's/|-//'|sed 's/|//'| sed -e 's/^[ \t]*//'|tr -s ' '"
+#define FILENAME "/proc/diskstats" //kernel reports sectors by 512 bytes even for AF 4kn
#define STAT_BUFSIZ 81920
-// Handle LVM and RAID //
-
-void
-find_primary_part (_partition_info *primary_part, const char *m)
-{
- int n = 0, tlvl = 0;
- char name[256]="",type[256]="";
-
- primary_part->max = 0;
-
- //scan by tree level
- //0 = disk (to lvl 0)
- //0 = disk, 1 = part (to lvl 1)
- //0 = disk, 1 = part, 2 = lvm or raid (to lvl 2)
- //0 = disk, 1 = part, 2 = raid, 3 = lvm (to lvl 3)
-
- while (sscanf(m, "%s %s", name, type) == 2)
- {
-
- if (tlvl == 0) {
-
- if (strcmp (type, "disk") == 0) {
-
- primary_part->max++;
-
- }
- else if ((strcmp (type, "part") == 0)){
-
- tlvl = 1;
-
- }
-
- }
- else if(tlvl == 1){
-
- if (strcmp (type, "disk") == 0) {
-
- n--;
- tlvl = 0;
- primary_part->max++;
-
- }
- else if ((strcmp (type, "part") == 0)) {
-
- n--;
-
- }
- else if ((strcmp (type, "lvm") == 0)) {
-
- tlvl = 2;
- primary_part->max++;
-
- }
- else if ((strncmp (type, "raid", 4) == 0)) {
-
- tlvl = 2;
- primary_part->max++;
-
- }
-
- }
- else if( tlvl == 2){
-
- if (strcmp(type, "disk") == 0) {
-
- n--;
- tlvl = 0;
- primary_part->max++;
-
- }
- else if ((strcmp (primary_part[n-1].type, "lvm") == 0) && (strcmp (type, "lvm") == 0)) {
-
- n--;
-
- }
- else if ((strcmp (primary_part[n-1].type, "raid") == 0) && (strncmp (type, "raid", 4) == 0)) {
-
- n--;
-
- }
- else if ((strcmp (primary_part[n-1].type, "lvm") == 0) && (strcmp (type, "part") == 0)) {
-
- n--;
- tlvl = 1;
-
- }
- else if ((strcmp (primary_part[n-1].type, "raid") == 0) && (strcmp (type, "part") == 0)) {
-
- n--;
- tlvl = 1;
-
- }
- else if ((strcmp (primary_part[n-1].type, "raid") == 0) && (strcmp (type, "lvm") == 0)){
-
- tlvl = 3;
- primary_part->max++;
-
- }
-
- }
- else if (tlvl == 3) {
-
- if (strcmp (type, "disk") == 0) {
-
- n--;
- tlvl = 0;
- primary_part->max++;
-
- }
- else if ((strcmp (type, "lvm") == 0)) {
-
- n--;
-
- }
- else if ((strncmp (type, "raid", 4) == 0)) {
-
- n--;
- tlvl = 2;
-
- }
- else if ((strcmp (type, "part") == 0)) {
-
- n--;
- tlvl = 1;
-
- }
- }
-
-
- strcpy (primary_part[n].name, name);
- strncpy (primary_part[n].type, type, 4);
-
- if (strcmp (primary_part[n].type, "raid") == 0) {
-
- strcpy (primary_part[n].raid_num, type + 4);
-
- }
-
- m = skip_line (m);
- n++;
-
- }
-}
-
-int
-is_virtual_drive (_partition_info *primary_part, const char *p)
-{
- int i;
- char name[256];
- int test = 1;
- sscanf (p, "%s", name);
-
- if (*p) {
-
- for (i=0; i<primary_part->max; i++) {
-
- if (strcmp (primary_part[i].name, name) == 0) {
-
- test = 0;
- break;
-
- }
-
- }
-
- }
- else {
-
- test = 0;
-
- }
-
- return test;
-}
-
void
glibtop_get_disk_s (glibtop *server, glibtop_disk *buf)
{
- _partition_info primary_part[GLIBTOP_NDISK];
- char buffer [STAT_BUFSIZ], *p, map_buffer [STAT_BUFSIZ], *m;
+ char buffer [STAT_BUFSIZ], *p;
int i;
memset (buf, 0, sizeof (glibtop_disk));
- file_to_buffer (server, buffer, sizeof buffer, FILENAME);
-
- get_from_pipe (map_buffer, CMD_PIPE);
-
- server->ndisk = GLIBTOP_NDISK;
+ file_to_buffer(server, buffer, sizeof buffer, FILENAME);
/*
* GLOBAL
*/
p = buffer; /* "disk" */
- m = map_buffer;
/*
* PER DISK
*/
- find_primary_part (primary_part, m);
-
for (i = 0; i <= server->ndisk; i++) {
- p = skip_multiple_token (p,2);
+ p = skip_multiple_token(p,2);
- // skip if disk is the raw device
- if (!is_virtual_drive (primary_part, p)) {
+ // skip if disk is the raw device
+ if(!check_alphanumeric_word(p)){
- p = skip_line (p); /* move to ^ */
- p = skip_multiple_token (p, 2);
+ p = skip_line(p); /* move to ^ */
+ p = skip_multiple_token(p,2);
- }
+ }
- if (!check_disk_line_warn (server, p, i))
+ if (!check_disk_line_warn(server, p, i))
break;
- p = skip_token (p); /* prev xdisk_name */
- p = skip_token (p); /* prev xdisk_reads_completed */
- p = skip_token (p); /* prev xdisk_reads_merged */
+ p = skip_token(p); /* prev xdisk_name */
+ p = skip_token(p); /* prev xdisk_reads_completed */
+ p = skip_token(p); /* prev xdisk_reads_merged */
buf->xdisk_sectors_read [i] = strtoull (p, &p, 0);
buf->xdisk_time_read [i] = strtoull (p, &p, 0);
- p = skip_token (p); /* prev xdisk_writes_completed */
- p = skip_token (p); /* prev xdisk_writes_merged */
+ p = skip_token(p); /* prev xdisk_writes_completed */
+ p = skip_token(p); /* prev xdisk_writes_merged */
buf->xdisk_sectors_write [i] = strtoull (p, &p, 0);
buf->xdisk_time_write [i] = strtoull (p, &p, 0);
- p = skip_line (p); /* move to ^ */
+ p = skip_line(p); /* move to ^ */
}
}
diff --git a/sysdeps/linux/glibtop_private.c b/sysdeps/linux/glibtop_private.c
index 7bca42a5..7b36561c 100644
--- a/sysdeps/linux/glibtop_private.c
+++ b/sysdeps/linux/glibtop_private.c
@@ -57,20 +57,21 @@ skip_token (const char *p)
}
-void
-get_from_pipe (char *buffer, const char *cmd)
+int
+check_alphanumeric_word (const char *p)
{
- FILE* fp;
- long psize;
-
- fp = popen (cmd, "r");
-
- fseek (fp, 0, SEEK_END);
- psize = ftell (fp);
- fseek (fp, 0, SEEK_SET);
- fread(buffer,1,psize,fp);
-
- pclose (fp);
+ int test = 0;
+ p = next_token(p);
+ while (*p && !g_ascii_isspace(*p)) {
+ if(g_ascii_isalpha(*p)){
+ test = 0;
+ }else if(g_ascii_isdigit(*p)){
+ test = 1;
+ }
+ p++;
+ };
+ p = next_token(p);
+ return test;
}
diff --git a/sysdeps/linux/glibtop_private.h b/sysdeps/linux/glibtop_private.h
index 66fed54c..d42ee669 100644
--- a/sysdeps/linux/glibtop_private.h
+++ b/sysdeps/linux/glibtop_private.h
@@ -61,8 +61,8 @@ skip_line (const char *p)
return (char *) (*p ? p+1 : p);
}
-void
-get_from_pipe (char *buffer, const char *cmd)
+int
+check_alphanumeric_word (const char *p);
/*
* Smart strtoul which handles binary suffixes