vgetvnode-debuglog-vio-20071228
[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 RCSID
14     ("$Header$");
15
16 #include <stdio.h>
17
18 #include <afs/cmd.h>
19
20 #include <rx/xdr.h>
21 #include <afs/afsint.h>
22 #include "nfs.h"
23 #include "lock.h"
24 #include "ihandle.h"
25 #include "vnode.h"
26 #include "volume.h"
27
28 int VolumeChanged; /* to keep physio happy */
29
30 static int
31 handleit(struct cmd_syndesc *as, void *arock)
32 {
33     Volume *vp;
34     Error ec;
35     int bless, unbless, nofssync;
36     int volumeId;
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 (VInitVolumePackage(nofssync ? salvager : volumeUtility, 5, 5, 1, 0)) {
49         fprintf(stderr,"Unable to initialize volume package\n");
50         exit(1);
51     }
52
53     vp = VAttachVolume(&ec, volumeId, V_VOLUPD);
54     if (ec) {
55         fprintf(stderr,"VAttachVolume failed: %d\n", ec);
56         exit(1);
57     }
58     if (bless) V_blessed(vp) = 1;
59     if (unbless) V_blessed(vp) = 0;
60     VUpdateVolume(&ec, vp);
61     if (ec) {
62         fprintf(stderr,"VUpdateVolume failed: %d\n", ec);
63         VPutVolume(vp);
64         exit(1);
65     }
66     VPutVolume(vp);
67     return 0;
68 }
69
70 int
71 main(int argc, char **argv)
72 {
73     register struct cmd_syndesc *ts;
74     afs_int32 code;
75
76     ts = cmd_CreateSyntax(NULL, handleit, NULL, "Manipulate volume blessed bit");
77     cmd_AddParm(ts, "-id", CMD_SINGLE, CMD_REQUIRED, "Volume id");
78     cmd_AddParm(ts, "-bless", CMD_FLAG, CMD_OPTIONAL, "Set blessed bit");
79     cmd_AddParm(ts, "-unbless", CMD_FLAG, CMD_OPTIONAL, "Clear blessed bit");
80     cmd_AddParm(ts, "-nofssync", CMD_FLAG, CMD_OPTIONAL,
81                 "Don't communicate with running fileserver");
82     code = cmd_Dispatch(argc, argv);
83     return code;
84 }
85
86