Import Upstream version 1.8.5
[hcoop/debian/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 #include <roken.h>
14
15 #include <afs/cmd.h>
16
17 #include <rx/xdr.h>
18 #include <afs/afsint.h>
19 #include "nfs.h"
20 #include "lock.h"
21 #include "ihandle.h"
22 #include "vnode.h"
23 #include "volume.h"
24
25 int VolumeChanged; /* to keep physio happy */
26
27 static int
28 handleit(struct cmd_syndesc *as, void *arock)
29 {
30 Volume *vp;
31 Error ec;
32 int bless, unbless, nofssync;
33 int volumeId;
34 VolumePackageOptions opts;
35 ProgramType pt;
36
37 volumeId = atoi(as->parms[0].items->data);
38 bless = !!(as->parms[1].items);
39 unbless = !!(as->parms[2].items);
40 nofssync = !!(as->parms[3].items);
41
42 if (bless && unbless) {
43 fprintf(stderr,"Cannot use both -bless and -unbless\n");
44 exit(1);
45 }
46
47 if (nofssync) {
48 pt = salvager;
49 } else {
50 pt = volumeUtility;
51 }
52
53 VOptDefaults(pt, &opts);
54 opts.canUseFSSYNC = !nofssync;
55
56 if (VInitVolumePackage2(pt, &opts)) {
57 fprintf(stderr,"Unable to initialize volume package\n");
58 exit(1);
59 }
60
61 vp = VAttachVolume(&ec, volumeId, V_VOLUPD);
62 if (ec) {
63 fprintf(stderr,"VAttachVolume failed: %d\n", ec);
64 exit(1);
65 }
66 if (bless) V_blessed(vp) = 1;
67 if (unbless) V_blessed(vp) = 0;
68 VUpdateVolume(&ec, vp);
69 if (ec) {
70 fprintf(stderr,"VUpdateVolume failed: %d\n", ec);
71 VDetachVolume(&ec, vp);
72 exit(1);
73 }
74 VDetachVolume(&ec, vp);
75 return 0;
76 }
77
78 int
79 main(int argc, char **argv)
80 {
81 struct cmd_syndesc *ts;
82 afs_int32 code;
83
84 ts = cmd_CreateSyntax(NULL, handleit, NULL, 0, "Manipulate volume blessed bit");
85 cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_REQUIRED, "Volume id");
86 cmd_AddParm(ts, "-bless", CMD_FLAG, CMD_OPTIONAL, "Set blessed bit");
87 cmd_AddParm(ts, "-unbless", CMD_FLAG, CMD_OPTIONAL, "Clear blessed bit");
88 cmd_AddParm(ts, "-nofssync", CMD_FLAG, CMD_OPTIONAL,
89 "Don't communicate with running fileserver");
90 code = cmd_Dispatch(argc, argv);
91 return code;
92 }
93
94