6f4eb8fa1f6efff5d6db68304bd76d6a34ad25dd
[openafs.git] / src / vol / vol-bless.c
1 /*
2  * Copyright 2004, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  *
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 #include <afsconfig.h>
11 #include <afs/param.h>
12
13
14 #include <stdio.h>
15
16 #include <afs/cmd.h>
17
18 #include <rx/xdr.h>
19 #include <afs/afsint.h>
20 #include "nfs.h"
21 #include "lock.h"
22 #include "ihandle.h"
23 #include "vnode.h"
24 #include "volume.h"
25
26 int VolumeChanged; /* to keep physio happy */
27
28 static int
29 handleit(struct cmd_syndesc *as, void *arock)
30 {
31     Volume *vp;
32     Error ec;
33     int bless, unbless, nofssync;
34     int volumeId;
35     VolumePackageOptions opts;
36     ProgramType pt;
37
38     volumeId = atoi(as->parms[0].items->data);
39     bless    = !!(as->parms[1].items);
40     unbless  = !!(as->parms[2].items);
41     nofssync = !!(as->parms[3].items);
42
43     if (bless && unbless) {
44         fprintf(stderr,"Cannot use both -bless and -unbless\n");
45         exit(1);
46     }
47
48     if (nofssync) {
49         pt = salvager;
50     } else {
51         pt = volumeUtility;
52     }
53
54     VOptDefaults(pt, &opts);
55     opts.canUseFSSYNC = !nofssync;
56
57     if (VInitVolumePackage2(pt, &opts)) {
58         fprintf(stderr,"Unable to initialize volume package\n");
59         exit(1);
60     }
61
62     vp = VAttachVolume(&ec, volumeId, V_VOLUPD);
63     if (ec) {
64         fprintf(stderr,"VAttachVolume failed: %d\n", ec);
65         exit(1);
66     }
67     if (bless) V_blessed(vp) = 1;
68     if (unbless) V_blessed(vp) = 0;
69     VUpdateVolume(&ec, vp);
70     if (ec) {
71         fprintf(stderr,"VUpdateVolume failed: %d\n", ec);
72         VDetachVolume(&ec, vp);
73         exit(1);
74     }
75     VDetachVolume(&ec, vp);
76     return 0;
77 }
78
79 int
80 main(int argc, char **argv)
81 {
82     struct cmd_syndesc *ts;
83     afs_int32 code;
84
85     ts = cmd_CreateSyntax(NULL, handleit, NULL, "Manipulate volume blessed bit");
86     cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_REQUIRED, "Volume id");
87     cmd_AddParm(ts, "-bless", CMD_FLAG, CMD_OPTIONAL, "Set blessed bit");
88     cmd_AddParm(ts, "-unbless", CMD_FLAG, CMD_OPTIONAL, "Clear blessed bit");
89     cmd_AddParm(ts, "-nofssync", CMD_FLAG, CMD_OPTIONAL,
90                 "Don't communicate with running fileserver");
91     code = cmd_Dispatch(argc, argv);
92     return code;
93 }
94
95