1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
|
From 7005b2ddaab5fe3c9e78d3c326dacbb4946a5501 Mon Sep 17 00:00:00 2001
From: Justus Winter <4winter@informatik.uni-hamburg.de>
Date: Sun, 18 May 2014 14:06:30 +0200
Subject: [PATCH 11/11] trans/fakeroot: use netfs_node_netnode instead of
np->nn
When using fat nodes, expressions of the form E->nn can be rewritten
as netfs_node_netnode (E). This is much faster as it only involves a
offset calculation. For reference, I used the following semantic
patch to create the patch:
@@
expression E;
@@
- E->nn
+ netfs_node_netnode (E)
* trans/fakeroot.c: Use netfs_node_netnode instead of np->nn.
---
trans/fakeroot.c | 99 ++++++++++++++++++++++++++++++--------------------------
1 file changed, 53 insertions(+), 46 deletions(-)
diff --git a/trans/fakeroot.c b/trans/fakeroot.c
index 59f8a86..32a34ec 100644
--- a/trans/fakeroot.c
+++ b/trans/fakeroot.c
@@ -125,7 +125,7 @@ new_node (file_t file, mach_port_t idport, int locked, int openmodes,
static void
set_default_attributes (struct node *np)
{
- np->nn->faked = FAKE_UID | FAKE_GID | FAKE_DEFAULT;
+ netfs_node_netnode (np)->faked = FAKE_UID | FAKE_GID | FAKE_DEFAULT;
np->nn_stat.st_uid = 0;
np->nn_stat.st_gid = 0;
}
@@ -133,9 +133,9 @@ set_default_attributes (struct node *np)
static void
set_faked_attribute (struct node *np, unsigned int faked)
{
- np->nn->faked |= faked;
+ netfs_node_netnode (np)->faked |= faked;
- if (np->nn->faked & FAKE_DEFAULT)
+ if (netfs_node_netnode (np)->faked & FAKE_DEFAULT)
{
/* Now that the node has non-default faked attributes, they have to be
retained for future accesses. Account for the hash table reference.
@@ -146,7 +146,7 @@ set_faked_attribute (struct node *np, unsigned int faked)
easy enough if it's ever needed, although scalability could be
improved. */
netfs_nref (np);
- np->nn->faked &= ~FAKE_DEFAULT;
+ netfs_node_netnode (np)->faked &= ~FAKE_DEFAULT;
}
}
@@ -158,11 +158,11 @@ netfs_node_norefs (struct node *np)
pthread_spin_unlock (&netfs_node_refcnt_lock);
pthread_mutex_lock (&idport_ihash_lock);
- hurd_ihash_locp_remove (&idport_ihash, np->nn->idport_locp);
+ hurd_ihash_locp_remove (&idport_ihash, netfs_node_netnode (np)->idport_locp);
pthread_mutex_unlock (&idport_ihash_lock);
- mach_port_deallocate (mach_task_self (), np->nn->file);
- mach_port_deallocate (mach_task_self (), np->nn->idport);
+ mach_port_deallocate (mach_task_self (), netfs_node_netnode (np)->file);
+ mach_port_deallocate (mach_task_self (), netfs_node_netnode (np)->idport);
free (np);
pthread_spin_lock (&netfs_node_refcnt_lock);
@@ -245,7 +245,8 @@ error_t
netfs_check_open_permissions (struct iouser *user, struct node *np,
int flags, int newnode)
{
- return check_openmodes (np->nn, flags & (O_RDWR|O_EXEC), MACH_PORT_NULL);
+ return check_openmodes (netfs_node_netnode (np),
+ flags & (O_RDWR|O_EXEC), MACH_PORT_NULL);
}
error_t
@@ -271,12 +272,12 @@ netfs_S_dir_lookup (struct protid *diruser,
dnp = diruser->po->np;
- mach_port_t dir = dnp->nn->file;
+ mach_port_t dir = netfs_node_netnode (dnp)->file;
redo_lookup:
err = dir_lookup (dir, filename,
flags & (O_NOLINK|O_RDWR|O_EXEC|O_CREAT|O_EXCL|O_NONBLOCK),
mode, do_retry, retry_name, &file);
- if (dir != dnp->nn->file)
+ if (dir != netfs_node_netnode (dnp)->file)
mach_port_deallocate (mach_task_self (), dir);
if (err)
return err;
@@ -380,7 +381,8 @@ netfs_S_dir_lookup (struct protid *diruser,
pthread_mutex_unlock (&dnp->lock);
}
- err = check_openmodes (np->nn, (flags & (O_RDWR|O_EXEC)), file);
+ err = check_openmodes (netfs_node_netnode (np),
+ (flags & (O_RDWR|O_EXEC)), file);
pthread_mutex_unlock (&idport_ihash_lock);
}
else
@@ -448,17 +450,17 @@ error_t
netfs_validate_stat (struct node *np, struct iouser *cred)
{
struct stat st;
- error_t err = io_stat (np->nn->file, &st);
+ error_t err = io_stat (netfs_node_netnode (np)->file, &st);
if (err)
return err;
- if (np->nn->faked & FAKE_UID)
+ if (netfs_node_netnode (np)->faked & FAKE_UID)
st.st_uid = np->nn_stat.st_uid;
- if (np->nn->faked & FAKE_GID)
+ if (netfs_node_netnode (np)->faked & FAKE_GID)
st.st_gid = np->nn_stat.st_gid;
- if (np->nn->faked & FAKE_AUTHOR)
+ if (netfs_node_netnode (np)->faked & FAKE_AUTHOR)
st.st_author = np->nn_stat.st_author;
- if (np->nn->faked & FAKE_MODE)
+ if (netfs_node_netnode (np)->faked & FAKE_MODE)
st.st_mode = np->nn_stat.st_mode;
np->nn_stat = st;
@@ -528,7 +530,7 @@ netfs_attempt_chmod (struct iouser *cred, struct node *np, mode_t mode)
/* We don't bother with error checking since the fake mode change should
always succeed--worst case a later open will get EACCES. */
- (void) file_chmod (np->nn->file, mode);
+ (void) file_chmod (netfs_node_netnode (np)->file, mode);
set_faked_attribute (np, FAKE_MODE);
np->nn_stat.st_mode = mode;
return 0;
@@ -543,7 +545,7 @@ netfs_attempt_mksymlink (struct iouser *cred, struct node *np, char *name)
char trans[sizeof _HURD_SYMLINK + namelen];
memcpy (trans, _HURD_SYMLINK, sizeof _HURD_SYMLINK);
memcpy (&trans[sizeof _HURD_SYMLINK], name, namelen);
- return file_set_translator (np->nn->file,
+ return file_set_translator (netfs_node_netnode (np)->file,
FS_TRANS_EXCL|FS_TRANS_SET,
FS_TRANS_EXCL|FS_TRANS_SET, 0,
trans, sizeof trans,
@@ -562,7 +564,7 @@ netfs_attempt_mkdev (struct iouser *cred, struct node *np,
return ENOMEM;
else
{
- error_t err = file_set_translator (np->nn->file,
+ error_t err = file_set_translator (netfs_node_netnode (np)->file,
FS_TRANS_EXCL|FS_TRANS_SET,
FS_TRANS_EXCL|FS_TRANS_SET, 0,
trans, translen + 1,
@@ -576,7 +578,7 @@ netfs_attempt_mkdev (struct iouser *cred, struct node *np,
error_t
netfs_attempt_chflags (struct iouser *cred, struct node *np, int flags)
{
- return file_chflags (np->nn->file, flags);
+ return file_chflags (netfs_node_netnode (np)->file, flags);
}
error_t
@@ -602,25 +604,25 @@ netfs_attempt_utimes (struct iouser *cred, struct node *np,
else
m.tv.tv_sec = m.tv.tv_usec = -1;
- return file_utimes (np->nn->file, a.tvt, m.tvt);
+ return file_utimes (netfs_node_netnode (np)->file, a.tvt, m.tvt);
}
error_t
netfs_attempt_set_size (struct iouser *cred, struct node *np, off_t size)
{
- return file_set_size (np->nn->file, size);
+ return file_set_size (netfs_node_netnode (np)->file, size);
}
error_t
netfs_attempt_statfs (struct iouser *cred, struct node *np, struct statfs *st)
{
- return file_statfs (np->nn->file, st);
+ return file_statfs (netfs_node_netnode (np)->file, st);
}
error_t
netfs_attempt_sync (struct iouser *cred, struct node *np, int wait)
{
- return file_sync (np->nn->file, wait, 0);
+ return file_sync (netfs_node_netnode (np)->file, wait, 0);
}
error_t
@@ -633,7 +635,7 @@ error_t
netfs_attempt_mkdir (struct iouser *user, struct node *dir,
char *name, mode_t mode)
{
- return dir_mkdir (dir->nn->file, name, mode | S_IRWXU);
+ return dir_mkdir (netfs_node_netnode (dir)->file, name, mode | S_IRWXU);
}
@@ -645,7 +647,7 @@ netfs_attempt_mkdir (struct iouser *user, struct node *dir,
error_t
netfs_attempt_unlink (struct iouser *user, struct node *dir, char *name)
{
- return dir_unlink (dir->nn->file, name);
+ return dir_unlink (netfs_node_netnode (dir)->file, name);
}
error_t
@@ -653,22 +655,22 @@ netfs_attempt_rename (struct iouser *user, struct node *fromdir,
char *fromname, struct node *todir,
char *toname, int excl)
{
- return dir_rename (fromdir->nn->file, fromname,
- todir->nn->file, toname, excl);
+ return dir_rename (netfs_node_netnode (fromdir)->file, fromname,
+ netfs_node_netnode (todir)->file, toname, excl);
}
error_t
netfs_attempt_rmdir (struct iouser *user,
struct node *dir, char *name)
{
- return dir_rmdir (dir->nn->file, name);
+ return dir_rmdir (netfs_node_netnode (dir)->file, name);
}
error_t
netfs_attempt_link (struct iouser *user, struct node *dir,
struct node *file, char *name, int excl)
{
- return dir_link (dir->nn->file, file->nn->file, name, excl);
+ return dir_link (netfs_node_netnode (dir)->file, netfs_node_netnode (file)->file, name, excl);
}
error_t
@@ -676,7 +678,7 @@ netfs_attempt_mkfile (struct iouser *user, struct node *dir,
mode_t mode, struct node **np)
{
file_t newfile;
- error_t err = dir_mkfile (dir->nn->file, O_RDWR|O_EXEC,
+ error_t err = dir_mkfile (netfs_node_netnode (dir)->file, O_RDWR|O_EXEC,
real_from_fake_mode (mode), &newfile);
pthread_mutex_unlock (&dir->lock);
if (err == 0)
@@ -692,7 +694,8 @@ netfs_attempt_readlink (struct iouser *user, struct node *np, char *buf)
char transbuf[sizeof _HURD_SYMLINK + np->nn_stat.st_size + 1];
char *trans = transbuf;
size_t translen = sizeof transbuf;
- error_t err = file_get_translator (np->nn->file, &trans, &translen);
+ error_t err = file_get_translator (netfs_node_netnode (np)->file,
+ &trans, &translen);
if (err == 0)
{
if (translen < sizeof _HURD_SYMLINK
@@ -715,7 +718,8 @@ netfs_attempt_read (struct iouser *cred, struct node *np,
off_t offset, size_t *len, void *data)
{
char *buf = data;
- error_t err = io_read (np->nn->file, &buf, len, offset, *len);
+ error_t err = io_read (netfs_node_netnode (np)->file,
+ &buf, len, offset, *len);
if (err == 0 && buf != data)
{
memcpy (data, buf, *len);
@@ -728,7 +732,7 @@ error_t
netfs_attempt_write (struct iouser *cred, struct node *np,
off_t offset, size_t *len, void *data)
{
- return io_write (np->nn->file, data, *len, offset, len);
+ return io_write (netfs_node_netnode (np)->file, data, *len, offset, len);
}
error_t
@@ -744,7 +748,7 @@ netfs_get_dirents (struct iouser *cred, struct node *dir,
mach_msg_type_number_t *datacnt,
vm_size_t bufsize, int *amt)
{
- return dir_readdir (dir->nn->file, data, datacnt,
+ return dir_readdir (netfs_node_netnode (dir)->file, data, datacnt,
entry, nentries, bufsize, amt);
}
@@ -762,7 +766,7 @@ netfs_file_get_storage_info (struct iouser *cred,
mach_msg_type_number_t *data_len)
{
*ports_type = MACH_MSG_TYPE_MOVE_SEND;
- return file_get_storage_info (np->nn->file,
+ return file_get_storage_info (netfs_node_netnode (np)->file,
ports, num_ports,
ints, num_ints,
offsets, num_offsets,
@@ -795,8 +799,9 @@ netfs_S_file_exec (struct protid *user,
return EOPNOTSUPP;
pthread_mutex_lock (&user->po->np->lock);
- err = check_openmodes (user->po->np->nn, O_EXEC, MACH_PORT_NULL);
- file = user->po->np->nn->file;
+ err = check_openmodes (netfs_node_netnode (user->po->np),
+ O_EXEC, MACH_PORT_NULL);
+ file = netfs_node_netnode (user->po->np)->file;
if (!err)
err = mach_port_mod_refs (mach_task_self (),
file, MACH_PORT_RIGHT_SEND, 1);
@@ -806,7 +811,8 @@ netfs_S_file_exec (struct protid *user,
{
/* We cannot use MACH_MSG_TYPE_MOVE_SEND because we might need to
retry an interrupted call that would have consumed the rights. */
- err = file_exec (user->po->np->nn->file, task, flags, argv, argvlen,
+ err = file_exec (netfs_node_netnode (user->po->np)->file,
+ task, flags, argv, argvlen,
envp, envplen, fds, MACH_MSG_TYPE_COPY_SEND, fdslen,
portarray, MACH_MSG_TYPE_COPY_SEND, portarraylen,
intarray, intarraylen, deallocnames, deallocnameslen,
@@ -838,7 +844,7 @@ netfs_S_io_map (struct protid *user,
*rdobjtype = *wrobjtype = MACH_MSG_TYPE_MOVE_SEND;
pthread_mutex_lock (&user->po->np->lock);
- err = io_map (user->po->np->nn->file, rdobj, wrobj);
+ err = io_map (netfs_node_netnode (user->po->np)->file, rdobj, wrobj);
pthread_mutex_unlock (&user->po->np->lock);
return err;
}
@@ -855,7 +861,7 @@ netfs_S_io_map_cntl (struct protid *user,
*objtype = MACH_MSG_TYPE_MOVE_SEND;
pthread_mutex_lock (&user->po->np->lock);
- err = io_map_cntl (user->po->np->nn->file, obj);
+ err = io_map_cntl (netfs_node_netnode (user->po->np)->file, obj);
pthread_mutex_unlock (&user->po->np->lock);
return err;
}
@@ -876,7 +882,8 @@ netfs_S_io_identity (struct protid *user,
*idtype = *fsystype = MACH_MSG_TYPE_MOVE_SEND;
pthread_mutex_lock (&user->po->np->lock);
- err = io_identity (user->po->np->nn->file, id, fsys, fileno);
+ err = io_identity (netfs_node_netnode (user->po->np)->file,
+ id, fsys, fileno);
pthread_mutex_unlock (&user->po->np->lock);
return err;
}
@@ -891,7 +898,7 @@ netfs_S_##name (struct protid *user) \
return EOPNOTSUPP; \
\
pthread_mutex_lock (&user->po->np->lock); \
- err = name (user->po->np->nn->file); \
+ err = name (netfs_node_netnode (user->po->np)->file); \
pthread_mutex_unlock (&user->po->np->lock); \
return err; \
}
@@ -913,7 +920,7 @@ netfs_S_io_prenotify (struct protid *user,
return EOPNOTSUPP;
pthread_mutex_lock (&user->po->np->lock);
- err = io_prenotify (user->po->np->nn->file, start, stop);
+ err = io_prenotify (netfs_node_netnode (user->po->np)->file, start, stop);
pthread_mutex_unlock (&user->po->np->lock);
return err;
}
@@ -928,7 +935,7 @@ netfs_S_io_postnotify (struct protid *user,
return EOPNOTSUPP;
pthread_mutex_lock (&user->po->np->lock);
- err = io_postnotify (user->po->np->nn->file, start, stop);
+ err = io_postnotify (netfs_node_netnode (user->po->np)->file, start, stop);
pthread_mutex_unlock (&user->po->np->lock);
return err;
}
@@ -971,7 +978,7 @@ netfs_demuxer (mach_msg_header_t *inp,
| MACH_MSGH_BITS (MACH_MSG_TYPE_COPY_SEND,
MACH_MSGH_BITS_REMOTE (inp->msgh_bits));
inp->msgh_local_port = inp->msgh_remote_port; /* reply port */
- inp->msgh_remote_port = cred->po->np->nn->file;
+ inp->msgh_remote_port = netfs_node_netnode (cred->po->np)->file;
err = mach_msg (inp, MACH_SEND_MSG, inp->msgh_size, 0,
MACH_PORT_NULL, MACH_MSG_TIMEOUT_NONE,
MACH_PORT_NULL);
--
2.0.0.rc2
|