Merge 1.8.0~pre4 packaging into master
[pkg-k5-afs_openafs.git] / src / vol / vol-bless.c
bloba28996f475819e67220e81eeaa33c81c64e85922
1 /*
2 * Copyright 2004, International Business Machines Corporation and others.
3 * All Rights Reserved.
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 */
10 #include <afsconfig.h>
11 #include <afs/param.h>
13 #include <roken.h>
15 #include <afs/cmd.h>
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"
25 int VolumeChanged; /* to keep physio happy */
27 static int
28 handleit(struct cmd_syndesc *as, void *arock)
30 Volume *vp;
31 Error ec;
32 int bless, unbless, nofssync;
33 int volumeId;
34 VolumePackageOptions opts;
35 ProgramType pt;
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);
42 if (bless && unbless) {
43 fprintf(stderr,"Cannot use both -bless and -unbless\n");
44 exit(1);
47 if (nofssync) {
48 pt = salvager;
49 } else {
50 pt = volumeUtility;
53 VOptDefaults(pt, &opts);
54 opts.canUseFSSYNC = !nofssync;
56 if (VInitVolumePackage2(pt, &opts)) {
57 fprintf(stderr,"Unable to initialize volume package\n");
58 exit(1);
61 vp = VAttachVolume(&ec, volumeId, V_VOLUPD);
62 if (ec) {
63 fprintf(stderr,"VAttachVolume failed: %d\n", ec);
64 exit(1);
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);
74 VDetachVolume(&ec, vp);
75 return 0;
78 int
79 main(int argc, char **argv)
81 struct cmd_syndesc *ts;
82 afs_int32 code;
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;