summaryrefslogtreecommitdiff
path: root/debian/patches/0013-xxx-half-assed-try-to-port-isofs-to-the-node-cache.patch
blob: 64cc167ebbfdd035ed0f25b657bb0e899afd7c42 (plain)
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
From 128449af8811d49a7cd4f8b686ad15e58a5ba19b Mon Sep 17 00:00:00 2001
From: Justus Winter <4winter@informatik.uni-hamburg.de>
Date: Wed, 15 Apr 2015 16:26:31 +0200
Subject: [PATCH hurd 13/16] xxx half-assed try to port isofs to the node cache

---
 isofs/inode.c  | 88 ++++++++++++++++++++++++++++------------------------------
 isofs/isofs.h  |  6 +++-
 isofs/lookup.c | 18 +++++++++---
 isofs/main.c   |  6 +++-
 isofs/rr.c     |  4 +++
 5 files changed, 70 insertions(+), 52 deletions(-)

diff --git a/isofs/inode.c b/isofs/inode.c
index e79ebdd..16abd86 100644
--- a/isofs/inode.c
+++ b/isofs/inode.c
@@ -40,8 +40,8 @@
 
 struct node_cache
 {
-  struct dirrect *dr;		/* somewhere in disk_image */
-  off_t file_start;		/* start of file */
+  //struct dirrect *dr;		/* somewhere in disk_image */
+  //off_t file_start;		/* start of file */
 
   off_t id;			/* UNIQUE identifier.  */
 
@@ -63,8 +63,7 @@ struct node_cache *node_cache = 0;
 static pthread_rwlock_t nodecache_lock = PTHREAD_RWLOCK_INITIALIZER;
 
 /* Forward */
-static error_t read_disknode (struct node *,
-			      struct dirrect *, struct rrip_lookup *);
+static error_t read_disknode (struct node *);
 
 
 /* Lookup node with id ID.  Returns NULL if the node is not found in
@@ -111,21 +110,14 @@ use_file_start_id (struct dirrect *record, struct rrip_lookup *rr)
 /* Enter NP into the cache.  The directory entry we used is DR, the
    cached Rock-Ridge info RR. nodecache_lock must be held. */
 void
-cache_inode (struct node *np, struct dirrect *record,
-	    struct rrip_lookup *rr)
+cache_inode (ino_t id, struct node *np)
 {
   int i;
   struct node_cache *c = 0;
-  off_t id;
-
-  if (use_file_start_id (record, rr))
-    id = np->dn->file_start << store->log2_block_size;
-  else
-    id = (off_t) ((void *) record - (void *) disk_image);
 
   /* First see if there's already an entry. */
   for (i = 0; i < node_cache_size; i++)
-    if (node_cache[i].id == id)
+    if (node_cache[i].id == (off_t) id)
       break;
 
   if (i == node_cache_size)
@@ -151,14 +143,9 @@ cache_inode (struct node *np, struct dirrect *record,
     }
 
   c = &node_cache[i];
-  c->id = id;
-  c->dr = record;
-  c->file_start = np->dn->file_start;
+  c->id = (off_t) id;
   diskfs_nref_light (np);
   c->np = np;
-
-  /* PLUS 1 so that we don't store zero cache ID's (not allowed by diskfs) */
-  np->cache_id = i + 1;
 }
 
 /* Fetch inode with cache id ID; set *NPP to the node structure;
@@ -177,7 +164,7 @@ diskfs_cached_lookup (ino_t id, struct node **npp)
   assert (id < node_cache_size);
 
   np = node_cache[id].np;
-
+  assert (np);
   if (!np)
     {
       struct node_cache *c = &node_cache[id];
@@ -186,7 +173,7 @@ diskfs_cached_lookup (ino_t id, struct node **npp)
 
       pthread_rwlock_unlock (&nodecache_lock);
 
-      rrip_lookup (node_cache[id].dr, &rr, 1);
+      //rrip_lookup (node_cache[id].dr, &rr, 1);
 
       /* We should never cache the wrong directory entry */
       assert (!(rr.valid & VALID_CL));
@@ -199,8 +186,8 @@ diskfs_cached_lookup (ino_t id, struct node **npp)
 	  return ENOMEM;
 	}
       dn->fileinfo = 0;
-      dn->dr = c->dr;
-      dn->file_start = c->file_start;
+      //dn->dr = c->dr;
+      //dn->file_start = c->file_start;
       np = diskfs_make_node (dn);
       if (!np)
 	{
@@ -224,7 +211,8 @@ diskfs_cached_lookup (ino_t id, struct node **npp)
       diskfs_nref_light (np);
       pthread_rwlock_unlock (&nodecache_lock);
 
-      err = read_disknode (np, dn->dr, &rr);
+      dn->rr = rr;
+      err = read_disknode (np);
       if (!err)
 	*npp = np;
 
@@ -327,33 +315,38 @@ calculate_file_start (struct dirrect *record, off_t *file_start,
   return 0;
 }
 
-
-/* Load the inode with directory entry RECORD and cached Rock-Ridge
-   info RR into NP.  The directory entry is at OFFSET in BLOCK.  */
+/* Given RECORD and RR, calculate the cache id.  */
 error_t
-load_inode (struct node **npp, struct dirrect *record,
-	    struct rrip_lookup *rr)
+cache_id (struct dirrect *record, struct rrip_lookup *rr, ino_t *idp)
 {
   error_t err;
   off_t file_start;
-  struct disknode *dn;
-  struct node *np, *tmp;
-  off_t id;
-
   err = calculate_file_start (record, &file_start, rr);
   if (err)
     return err;
+
   if (rr->valid & VALID_CL)
     record = rr->realdirent;
 
-  /* First check the cache */
   if (use_file_start_id (record, rr))
-    id = file_start << store->log2_block_size;
+    *idp = file_start << store->log2_block_size;
   else
-    id = (off_t) ((void *) record - (void *) disk_image);
+    *idp = (off_t) ((void *) record - (void *) disk_image);
+  return 0;
+}
+
+/* Load the inode with directory entry RECORD and cached Rock-Ridge
+   info RR into NP.  The directory entry is at OFFSET in BLOCK.  */
+error_t
+load_inode (ino_t id, struct node **npp, struct dirrect *record,
+            struct rrip_lookup *rr)
+{
+  error_t err;
+  struct disknode *dn;
+  struct node *np, *tmp;
 
   pthread_rwlock_rdlock (&nodecache_lock);
-  inode_cache_find (id, npp);
+  inode_cache_find ((off_t) id, npp);
   pthread_rwlock_unlock (&nodecache_lock);
   if (*npp)
     return 0;
@@ -363,9 +356,14 @@ load_inode (struct node **npp, struct dirrect *record,
   if (!dn)
     return ENOMEM;
 
+  err = calculate_file_start (record, &dn->file_start, rr);
+  if (err)
+    {
+      free (dn);
+      return err;
+    }
   dn->fileinfo = 0;
   dn->dr = record;
-  dn->file_start = file_start;
 
   np = diskfs_make_node (dn);
   if (!np)
@@ -388,10 +386,10 @@ load_inode (struct node **npp, struct dirrect *record,
       return 0;
     }
 
-  cache_inode (np, record, rr);
+  cache_inode (id, np);
   pthread_rwlock_unlock (&nodecache_lock);
 
-  err = read_disknode (np, record, rr);
+  err = read_disknode (np);
   *npp = np;
   return err;
 }
@@ -400,17 +398,15 @@ load_inode (struct node **npp, struct dirrect *record,
 /* Read stat information from the directory entry at DR and the
    contents of RL. */
 static error_t
-read_disknode (struct node *np, struct dirrect *dr,
-	       struct rrip_lookup *rl)
+read_disknode (struct node *np)
 {
   error_t err;
   struct stat *st = &np->dn_stat;
+  struct dirrect *dr = np->dn->dr;
+  struct rrip_lookup *rl = &np->dn->rr;
   st->st_fstype = FSTYPE_ISO9660;
   st->st_fsid = getpid ();
-  if (use_file_start_id (dr, rl))
-    st->st_ino = (ino_t) np->dn->file_start << store->log2_block_size;
-  else
-    st->st_ino = (ino_t) ((void *) dr - (void *) disk_image);
+  st->st_ino = np->cache_id;
   st->st_gen = 0;
   st->st_rdev = 0;
 
diff --git a/isofs/isofs.h b/isofs/isofs.h
index 68a94e9..9aa9608 100644
--- a/isofs/isofs.h
+++ b/isofs/isofs.h
@@ -34,6 +34,7 @@
 struct disknode
 {
   struct dirrect *dr; /* Somewhere in disk_image.  */
+  struct rrip_lookup rr;
 
   off_t file_start; /* In store->block_size units */
 
@@ -87,7 +88,10 @@ void drop_pager_softrefs (struct node *);
 void allow_pager_softrefs (struct node *);
 void create_disk_pager (void);
 
-error_t load_inode (struct node **, struct dirrect *, struct rrip_lookup *);
+/* Given RECORD and RR, calculate the cache id.  */
+error_t cache_id (struct dirrect *record, struct rrip_lookup *rr, ino_t *idp);
+
+error_t load_inode (ino_t, struct node **, struct dirrect *, struct rrip_lookup *);
 error_t calculate_file_start (struct dirrect *, off_t *, struct rrip_lookup *);
 
 char *isodate_915 (char *, struct timespec *);
diff --git a/isofs/lookup.c b/isofs/lookup.c
index e51b9cb..f0bd73b 100644
--- a/isofs/lookup.c
+++ b/isofs/lookup.c
@@ -76,6 +76,7 @@ diskfs_lookup_hard (struct node *dp, const char *name, enum lookup_type type,
   void *buf;
   void *blockaddr;
   struct rrip_lookup rr;
+  ino_t id;
 
   if ((type == REMOVE) || (type == RENAME))
     assert (npp);
@@ -115,6 +116,10 @@ diskfs_lookup_hard (struct node *dp, const char *name, enum lookup_type type,
   if (err)
     return err;
 
+  err = cache_id (record, &rr, &id);
+  if (err)
+    return err;
+
   /* Load the inode */
   if (namelen == 2 && name[0] == '.' && name[1] == '.')
     {
@@ -125,7 +130,7 @@ diskfs_lookup_hard (struct node *dp, const char *name, enum lookup_type type,
 	  /* renames and removes can't get this far. */
 	  assert (type == LOOKUP);
 	  diskfs_nput (dp);
-	  err = load_inode (npp, record, &rr);
+	  err = load_inode (id, npp, record, &rr);
 	}
       else
 	{
@@ -133,7 +138,7 @@ diskfs_lookup_hard (struct node *dp, const char *name, enum lookup_type type,
 	     we are permanently read-only, so things are necessarily
 	     quiescent.  Just be careful to honor the locking order. */
 	  pthread_mutex_unlock (&dp->lock);
-	  err = load_inode (npp, record, &rr);
+	  err = load_inode (id, npp, record, &rr);
 	  pthread_mutex_lock (&dp->lock);
 	}
     }
@@ -143,9 +148,14 @@ diskfs_lookup_hard (struct node *dp, const char *name, enum lookup_type type,
       diskfs_nref (dp);
     }
   else
-    err = load_inode (npp, record, &rr);
+    err = load_inode (id, npp, record, &rr);
+
+  (*npp)->dn->dr = record;
+  if ((*npp)->dn->rr.valid)
+    release_rrip (&rr);
+  else
+    (*npp)->dn->rr = rr;
 
-  release_rrip (&rr);
   return err;
 }
 
diff --git a/isofs/main.c b/isofs/main.c
index 4f531f7..fb111dd 100644
--- a/isofs/main.c
+++ b/isofs/main.c
@@ -46,6 +46,7 @@ fetch_root ()
 {
   struct rrip_lookup rl;
   struct dirrect *dr;
+  ino_t id;
   error_t err;
 
   dr = (struct dirrect *) sblock->root;
@@ -56,8 +57,11 @@ fetch_root ()
   /* Now rescan the node for real */
   rrip_lookup (dr, &rl, 1);
 
+  err = cache_id (dr, &rl, &id);
+  assert_perror (err);
+
   /* And fetch the node. */
-  err = load_inode (&diskfs_root_node, dr, &rl);
+  err = load_inode (id, &diskfs_root_node, dr, &rl);
   assert_perror (err);
 
   pthread_mutex_unlock (&diskfs_root_node->lock);
diff --git a/isofs/rr.c b/isofs/rr.c
index adc95c3..2429fae 100644
--- a/isofs/rr.c
+++ b/isofs/rr.c
@@ -38,10 +38,13 @@ release_rrip (struct rrip_lookup *rr)
 {
   if ((rr->valid & VALID_NM) && rr->name)
     free (rr->name);
+  rr->name = NULL;
   if ((rr->valid & VALID_SL) && rr->target)
     free (rr->target);
+  rr->target = NULL;
   if ((rr->valid & VALID_TR) && rr->trans)
     free (rr->trans);
+  rr->trans = NULL;
 }
 
 
@@ -51,6 +54,7 @@ rrip_work (struct dirrect *dr, struct rrip_lookup *rr,
 	   const char *match_name, size_t match_name_len,
 	   int initializing, int ignorenm)
 {
+  //  error (0, 0, "rrip_work %p %p %s %d %d %d", dr, rr, match_name, match_name_len, initializing, ignorenm);
   void *bp, *terminus;
   void *slbuf, *nmbuf;
   size_t slbufsize, nmbufsize;
-- 
2.1.4