Bug Summary

File:tsalvaged/./../vol/nuke.c
Location:line 195, column 2
Description:Value stored to 'code' is never read

Annotated Source Code

1/*
2 * Copyright 2000, 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 <rx/xdr.h>
16#include <afs/afsint.h>
17#include <afs/afs_assert.h>
18
19#include <afs/afsutil.h>
20
21#include "nfs.h"
22#include "lwp.h"
23#include "lock.h"
24#include <afs/afssyscalls.h>
25#include "ihandle.h"
26#include "vnode.h"
27#include "volume.h"
28#include "partition.h"
29#include "viceinode.h"
30#include "salvage.h"
31#include "daemon_com.h"
32#include "fssync.h"
33#include "common.h"
34
35struct Lock localLock;
36
37#define MAXATONCE100 100
38/* structure containing neatly packed set of inodes and the # of times we'll have
39 * to idec them in order to reclaim their storage. NukeProc, called by ListViceInodes,
40 * builds this list for us.
41 */
42struct ilist {
43 struct ilist *next;
44 afs_int32 freePtr; /* first free index in this table */
45 Inode inode[MAXATONCE100]; /* inode # */
46 afs_int32 count[MAXATONCE100]; /* link count */
47};
48
49/* called with a structure specifying info about the inode, and our rock (which
50 * is the volume ID. Returns true if we should keep this inode, otherwise false.
51 * Note that ainfo->u.param[0] is always the volume ID, for any vice inode.
52 */
53static int
54NukeProc(struct ViceInodeInfo *ainfo, afs_uint32 avolid, void *arock)
55{
56 struct ilist **allInodes = (struct ilist **)arock;
57 struct ilist *ti;
58 afs_int32 i;
59
60#ifndef AFS_PTHREAD_ENV1
61 IOMGR_Poll(); /* poll so we don't kill the RPC connection */
62#endif /* !AFS_PTHREAD_ENV */
63
64 /* check if this is the volume we're looking for */
65 if (ainfo->u.param[0] != avolid)
66 return 0; /* don't want this one */
67 /* record the info */
68 if (!*allInodes || (*allInodes)->freePtr >= MAXATONCE100) {
69 ti = (struct ilist *)malloc(sizeof(struct ilist));
70 memset(ti, 0, sizeof(*ti));
71 ti->next = *allInodes;
72 *allInodes = ti;
73 } else
74 ti = *allInodes; /* use the one with space */
75 i = ti->freePtr++; /* find our slot in this mess */
76 ti->inode[i] = ainfo->inodeNumber;
77 ti->count[i] = ainfo->linkCount;
78 return 0; /* don't care if anything's written out, actually */
79}
80
81/* function called with partition name and volid ID, and which removes all
82 * inodes marked with the specified volume ID. If the volume is a read-only
83 * clone, we'll only remove the header inodes, since they're the only inodes
84 * marked with that volume ID. If you want to reclaim all the data, you should
85 * nuke the read-write volume ID.
86 *
87 * Note also that nuking a read-write volume effectively nukes all RO volumes
88 * cloned from that RW volume ID, too, since everything except for their
89 * indices will be gone.
90 */
91int
92nuke(char *aname, afs_int32 avolid)
93{
94 /* first process the partition containing this junk */
95 struct afs_stat_ststat tstat;
96 struct ilist *ti, *ni, *li=NULL((void *)0);
97 afs_int32 code;
98 int i, forceSal;
99 char wpath[100];
100 char *lastDevComp;
101 struct DiskPartition64 *dp;
102#ifdef AFS_NAMEI_ENV1
103 char *path;
104
105 namei_t ufs_name;
106#endif /* AFS_NAMEI_ENV */
107#ifndef AFS_NAMEI_ENV1
108 char devName[64];
109#endif /* !AFS_NAMEI_ENV */
110 IHandle_t *fileH;
111 struct ilist *allInodes = 0;
112
113 if (avolid == 0)
114 return EINVAL22;
115 code = afs_statstat(aname, &tstat);
116 if (code || (dp = VGetPartition(aname, 0)) == NULL((void *)0)) {
117 printf("volnuke: partition %s does not exist.\n", aname);
118 if (!code) {
119 code = EINVAL22;
120 }
121 return code;
122 }
123 /* get the device name for the partition */
124#if defined(AFS_NAMEI_ENV1) && !defined(AFS_NT40_ENV)
125 lastDevComp = aname;
126#else
127#ifdef AFS_NT40_ENV
128 lastDevComp = &aname[strlen(aname) - 1];
129 *lastDevComp = toupper(*lastDevComp);
130#else
131 {
132 char *tfile = vol_DevName(tstat.st_dev, wpath);
133 if (!tfile) {
134 printf("volnuke: can't find %s's device.\n", aname);
135 return 1;
136 }
137 strcpy(devName, tfile); /* save this from the static buffer */
138 }
139 /* aim lastDevComp at the 'foo' of '/dev/foo' */
140 lastDevComp = strrchr(devName, OS_DIRSEPC'/');
141 /* either points at slash, or there is no slash; adjust appropriately */
142 if (lastDevComp)
143 lastDevComp++;
144 else
145 lastDevComp = devName;
146#endif /* AFS_NT40_ENV */
147#endif /* AFS_NAMEI_ENV && !AFS_NT40_ENV */
148
149 ObtainWriteLock(&localLock)do { (void)((pthread_mutex_lock(&(&localLock)->mutex
) == 0) || (osi_AssertFailU("pthread_mutex_lock(&(&localLock)->mutex) == 0"
, "./../vol/nuke.c", 149), 0));; if (!(&localLock)->excl_locked
&& !(&localLock)->readers_reading) (&localLock
) -> excl_locked = 2; else Afs_Lock_Obtain(&localLock,
2); (void)((pthread_mutex_unlock(&(&localLock)->mutex
) == 0) || (osi_AssertFailU("pthread_mutex_unlock(&(&localLock)->mutex) == 0"
, "./../vol/nuke.c", 149), 0));; } while (0)
;
150 /* OK, we have the mounted on place, aname, the device name (in devName).
151 * all we need to do to call ListViceInodes is find the inodes for the
152 * volume we're nuking.
153 */
154 code =
155 ListViceInodes(lastDevComp, aname, INVALID_FD((FD_t)-1), NukeProc, avolid, &forceSal,
156 0, wpath, &allInodes);
157 if (code == 0) {
158 /* actually do the idecs now */
159 for (ti = allInodes; ti; ti = ti->next) {
160 for (i = 0; i < ti->freePtr; i++) {
161#ifndef AFS_PTHREAD_ENV1
162 IOMGR_Poll(); /* keep RPC running */
163#endif /* !AFS_PTHREAD_ENV */
164 /* idec this inode into oblivion */
165#ifdef AFS_NAMEI_ENV1
166#ifdef AFS_NT40_ENV
167 IH_INIT(fileH, (int)(*lastDevComp - 'A'), avolid,((fileH) = ih_init(((int)(*lastDevComp - 'A')), (avolid), (ti
->inode[i])))
168 ti->inode[i])((fileH) = ih_init(((int)(*lastDevComp - 'A')), (avolid), (ti
->inode[i])))
;
169#else
170 IH_INIT(fileH, (int)volutil_GetPartitionID(aname), avolid,((fileH) = ih_init(((int)volutil_GetPartitionID(aname)), (avolid
), (ti->inode[i])))
171 ti->inode[i])((fileH) = ih_init(((int)volutil_GetPartitionID(aname)), (avolid
), (ti->inode[i])))
;
172#endif /* AFS_NT40_ENV */
173 namei_HandleToName(&ufs_name, fileH);
174 path = ufs_name.n_path;
175 IH_RELEASE(fileH)(ih_release(fileH), (fileH)=((void *)0), 0);
176 if (OS_UNLINK(path)unlink(path) < 0) {
177 Log("Nuke: Failed to remove %s\n", path);
178 }
179#else /* AFS_NAMEI_ENV */
180 IH_INIT(fileH, (int)tstat.st_dev, avolid, ti->inode[i])((fileH) = ih_init(((int)tstat.st_dev), (avolid), (ti->inode
[i])))
;
181 {
182 int j;
183 for (j = 0; j < ti->count[i]; j++) {
184 code = IH_DEC(fileH, ti->inode[i], avolid)namei_dec(fileH, ti->inode[i], avolid);
185 }
186 }
187 IH_RELEASE(fileH)(ih_release(fileH), (fileH)=((void *)0), 0);
188#endif /* AFS_NAMEI_ENV */
189 }
190 ni = ti->next;
191 if (li) free(li);
192 li = ti;
193 }
194 if (li) free(li);
195 code = 0; /* we really don't care about it except for debugging */
Value stored to 'code' is never read
196 allInodes = NULL((void *)0);
197
198 /* at this point, we should try to remove the volume header file itself.
199 * the volume header file is the file named VNNNNN.vol in the UFS file
200 * system, and is a normal file. As such, it is not stamped with the
201 * volume's ID in its inode, and has to be removed explicitly.
202 */
203 code = VDestroyVolumeDiskHeader(dp, avolid, 0);
204 } else {
205 /* just free things */
206 for (ti = allInodes; ti; ti = ni) {
207 ni = ti->next;
208 if (li) free(li);
209 li = ti;
210 }
211 if (li) free(li);
212 allInodes = NULL((void *)0);
213 }
214 ReleaseWriteLock(&localLock)do { (void)((pthread_mutex_lock(&(&localLock)->mutex
) == 0) || (osi_AssertFailU("pthread_mutex_lock(&(&localLock)->mutex) == 0"
, "./../vol/nuke.c", 214), 0));; (&localLock)->excl_locked
&= ~2; if ((&localLock)->wait_states) Afs_Lock_ReleaseR
(&localLock); (void)((pthread_mutex_unlock(&(&localLock
)->mutex) == 0) || (osi_AssertFailU("pthread_mutex_unlock(&(&localLock)->mutex) == 0"
, "./../vol/nuke.c", 214), 0));; } while (0)
;
215 return code;
216}