Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make lvmtscd read config file (use its parameters only as a fallback)

  • Loading branch information...
commit 961bb1a298d7318e5a20121b21503130ec66b369 1 parent 29d9d8a
@tomato42 authored
Showing with 78 additions and 42 deletions.
  1. +2 −2 Makefile
  2. +39 −0 config.c
  3. +4 −0 config.h
  4. +33 −3 lvmtscd.c
  5. +0 −37 lvmtsd.c
View
4 Makefile
@@ -26,8 +26,8 @@ lvmls: lvmls.c
lvmdefrag: lvmdefrag.c
$(CC) $(CFLAGS) lvmdefrag.c lvmls.o $(LFLAGS) -o lvmdefrag
-lvmtscd: lvmtscd.c activity_stats.o
- $(CC) $(CFLAGS) lvmtscd.c activity_stats.o -o lvmtscd
+lvmtscd: lvmtscd.c activity_stats.o config.o lvmls.o volumes.o extents.o
+ $(CC) $(CFLAGS) lvmtscd.c activity_stats.o config.o lvmls.o volumes.o extents.o $(LFLAGS) -o lvmtscd
lvmtscat: lvmtscat.c activity_stats.o lvmls.o
$(CC) $(CFLAGS) lvmtscat.c activity_stats.o lvmls.o $(LFLAGS) -o lvmtscat
View
39 config.c
@@ -23,7 +23,46 @@
#include <assert.h>
#include <string.h>
#include <errno.h>
+#include <lvm2cmd.h>
#include "config.h"
+#include "lvmls.h"
+
+/** Create new program_params with default settings */
+struct program_params*
+new_program_params()
+{
+ struct program_params *pp;
+
+ pp = calloc(sizeof(struct program_params),1);
+ if (!pp)
+ return NULL;
+
+ pp->conf_file_path = strdup("doc/sample.conf");
+
+ pp->cfg = NULL;
+
+ return pp;
+}
+
+/** destroy program_params */
+void
+free_program_params(struct program_params *pp)
+{
+ if(!pp)
+ return;
+
+ if(pp->conf_file_path)
+ free(pp->conf_file_path);
+
+ cfg_free(pp->cfg);
+
+ if (pp->lvm2_handle)
+ lvm2_exit(pp->lvm2_handle);
+
+ le_to_pe_exit(pp);
+
+ free(pp);
+}
float
get_read_multiplier(struct program_params *pp, const char *lv_name)
View
4 config.h
@@ -9,6 +9,10 @@ struct program_params {
cfg_t *cfg;
};
+struct program_params* new_program_params();
+
+void free_program_params(struct program_params *pp);
+
float get_read_multiplier(struct program_params *pp, const char *lv_name);
float get_write_multiplier(struct program_params *pp, const char *lv_name);
View
36 lvmtscd.c
@@ -30,7 +30,9 @@
#include <pthread.h>
#include <getopt.h>
#include <signal.h>
+#include "volumes.h"
#include "activity_stats.h"
+#include "config.h"
static int programEnd = 0;
@@ -370,7 +372,7 @@ void
ignoreHandler(int dummy) {
}
-struct program_params {
+struct lvmtscd_params {
size_t esize; /**< extent size */
int64_t granularity;
char *file;
@@ -378,6 +380,8 @@ struct program_params {
char *lv_dev_name;
int daemonize;
int show_help;
+ char *config_file;
+ struct program_params *pp;
};
void
@@ -391,11 +395,12 @@ usage(char *name) {
printf("\t-l,--lv-dev d Monitor device `d`\n");
printf("\t-d,--debug Don't daemonize, run in forground\n");
printf("\t--delay l How often write statistics to file (in seconds)\n");
+ printf("\t-c,--config c Name of config file\n");
printf("\t-?,--help This message\n");
}
int
-parse_arguments(int argc, char **argv, struct program_params *pp) {
+parse_arguments(int argc, char **argv, struct lvmtscd_params *pp) {
assert(pp);
int f_ret = 0;
int c;
@@ -417,6 +422,7 @@ parse_arguments(int argc, char **argv, struct program_params *pp) {
{"debug", no_argument, 0, 'd' }, // 4
{"help", no_argument, 0, '?' }, // 5
{"delay", required_argument, 0, 0 }, // 6
+ {"config", required_argument, 0, 'c'}, // 7
{0, 0, 0, 0}
};
@@ -481,6 +487,9 @@ parse_arguments(int argc, char **argv, struct program_params *pp) {
f_ret = 1;
goto usage;
break;
+ case 'c':
+ pp->config_file = optarg;
+ break;
default:
f_ret = 1;
fprintf(stderr, "Unknown option %c\n", c);
@@ -517,13 +526,33 @@ main(int argc, char **argv) {
struct thread_param *tp = malloc(sizeof(struct thread_param));
assert(tp);
- struct program_params pp = { 0 };
+ struct lvmtscd_params pp = { 0 };
if (parse_arguments(argc, argv, &pp)) {
free(tp);
return 1;
}
+ pp.pp = new_program_params();
+ if(!pp.pp) {
+ fprintf(stderr, "Out of memory error\n");
+ exit(1);
+ }
+
+ pp.pp->conf_file_path = pp.config_file;
+
+ ret = read_config(pp.pp);
+ if(ret) {
+ free_program_params(pp.pp);
+ exit(1);
+ }
+
+ const char *vol_name = get_first_volume_name(pp.pp);
+
+ if(!pp.lv_dev_name)
+ asprintf(&pp.lv_dev_name, "/dev/%s/%s", get_volume_vg(pp.pp, vol_name),
+ get_volume_lv(pp.pp, vol_name));
+
//activ = new_activity_stats_s(1<<10); // assume 2^11 extents (40GiB)
if(read_activity_stats(&activ, pp.file)) {
fprintf(stderr, "Can't read \"%s\". Ignoring.\n", pp.file);
@@ -573,6 +602,7 @@ main(int argc, char **argv) {
pthread_join(thread, &thret);
destroy_activity_stats(activ);
+ free_program_params(pp.pp);
fprintf(stderr, "done\n");
View
37 lvmtsd.c
@@ -35,43 +35,6 @@
/** variable defining ordered shutdown */
int stop = 0;
-/** Create new program_params with default settings */
-static struct program_params*
-new_program_params()
-{
- struct program_params *pp;
-
- pp = calloc(sizeof(struct program_params),1);
- if (!pp)
- return NULL;
-
- pp->conf_file_path = strdup("doc/sample.conf");
-
- pp->cfg = NULL;
-
- return pp;
-}
-
-/** destroy program_params */
-void
-free_program_params(struct program_params *pp)
-{
- if(!pp)
- return;
-
- if(pp->conf_file_path)
- free(pp->conf_file_path);
-
- cfg_free(pp->cfg);
-
- if (pp->lvm2_handle)
- lvm2_exit(pp->lvm2_handle);
-
- le_to_pe_exit(pp);
-
- free(pp);
-}
-
/** parse CLI arguments
* TODO
*/
Please sign in to comment.
Something went wrong with that request. Please try again.