* [Drbd-dev] Running drbdmeta non-interactively
@ 2006-07-14 21:02 Graham, Simon
2006-07-17 8:27 ` Philipp Reisner
0 siblings, 1 reply; 2+ messages in thread
From: Graham, Simon @ 2006-07-14 21:02 UTC (permalink / raw)
To: drbd-dev
[-- Attachment #1.1: Type: text/plain, Size: 454 bytes --]
Currently, drbdmeta always prompts for confirmation before updating
meta-data - this is fine for interactive use but if you want to
initialize meta-data programmatically (as part of provisioning a box for
example) it causes problems. I would propose adding a "-force" option to
drbdmeta that overrides this and assumes a 'yes' answer to all
questions.
I have coded this and a patch for trunk is attached.
Simon
<<drbdmeta-bug665.patch>>
[-- Attachment #1.2: Type: text/html, Size: 1779 bytes --]
[-- Attachment #2: drbdmeta-bug665.patch --]
[-- Type: application/octet-stream, Size: 2548 bytes --]
Index: drbdmeta.c
===================================================================
--- drbdmeta.c (revision 3050)
+++ drbdmeta.c (working copy)
@@ -36,6 +36,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
+#include <getopt.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
@@ -50,6 +51,13 @@
extern FILE* yyin;
YYSTYPE yylval;
+int force = 0;
+
+struct option metaopt[] = {
+ { "force", no_argument, 0, 'f' },
+ { NULL, 0, 0, 0 },
+};
+
#define PAGE_SIZE getpagesize()
#define PAGE_MASK (~(PAGE_SIZE-1))
#define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK)
@@ -792,11 +800,19 @@
size_t n = 0;
int ok;
- printf("\n%s\n[need to type '%s' to confirm] ", text, yes);
- ok = getline(&answer,&n,stdin) == N &&
- strncmp(answer,yes,N-1) == 0;
- if (answer) free(answer);
- printf("\n");
+ printf("\n%s\n", text);
+
+ if (force) {
+ printf("*** confirmation forced via --force option ***\n");
+ ok = 1;
+ }
+ else {
+ printf("[need to type '%s' to confirm] ", yes);
+ ok = getline(&answer,&n,stdin) == N &&
+ strncmp(answer,yes,N-1) == 0;
+ if (answer) free(answer);
+ printf("\n");
+ }
return ok;
}
@@ -2278,7 +2294,7 @@
size_t i;
printf
- ("\nUSAGE: %s DEVICE FORMAT [FORMAT ARGS...] COMMAND [CMD ARGS...]\n",
+ ("\nUSAGE: %s [--force] DEVICE FORMAT [FORMAT ARGS...] COMMAND [CMD ARGS...]\n",
progname);
printf("\nFORMATS:\n");
@@ -2408,14 +2424,32 @@
if (argc < 4)
print_usage_and_exit();
+ /* Check for options (e.g. --force) */
+ while (1) {
+ int c = getopt_long(argc,argv,make_optstring(metaopt,0),metaopt,0);
+
+ if (c == -1)
+ break;
+
+ switch (c) {
+ case 'f':
+ force = 1;
+ break;
+ default:
+ print_usage_and_exit();
+ break;
+ }
+ }
+
+ // Next argument to process is specified by optind...
+ ai = optind;
+
/* FIXME should have a "drbd_cfg_new" and a "drbd_cfg_free"
* function, maybe even a "get" and "put" ?
*/
cfg = calloc(1, sizeof(struct format));
- cfg->drbd_dev_name = argv[1];
+ cfg->drbd_dev_name = argv[ai++];
- /* argv[0] is progname, argv[1] was drbd_dev_name. */
- ai = 2;
if (parse_format(cfg, argv + ai, argc - ai, &ai)) {
/* parse has already printed some error message */
exit(20);
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [Drbd-dev] Running drbdmeta non-interactively
2006-07-14 21:02 [Drbd-dev] Running drbdmeta non-interactively Graham, Simon
@ 2006-07-17 8:27 ` Philipp Reisner
0 siblings, 0 replies; 2+ messages in thread
From: Philipp Reisner @ 2006-07-17 8:27 UTC (permalink / raw)
To: drbd-dev
Am Freitag, 14. Juli 2006 23:02 schrieb Graham, Simon:
> Currently, drbdmeta always prompts for confirmation before updating
> meta-data - this is fine for interactive use but if you want to
> initialize meta-data programmatically (as part of provisioning a box for
> example) it causes problems. I would propose adding a "-force" option to
> drbdmeta that overrides this and assumes a 'yes' answer to all
> questions.
>
> I have coded this and a patch for trunk is attached.
>
> Simon
>
> <<drbdmeta-bug665.patch>>
Applied...
-phil
--
: Dipl-Ing Philipp Reisner Tel +43-1-8178292-50 :
: LINBIT Information Technologies GmbH Fax +43-1-8178292-82 :
: Schönbrunnerstr 244, 1120 Vienna, Austria http://www.linbit.com :
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2006-07-17 8:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-07-14 21:02 [Drbd-dev] Running drbdmeta non-interactively Graham, Simon
2006-07-17 8:27 ` Philipp Reisner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox