summaryrefslogtreecommitdiff
path: root/debian/patches/ext2fs_large_stores_pthread.patch
blob: 71f76a34e5c072951520f2d5f53a4589bdf80065 (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
commit 93691ae1ae88c2d66d240b50e3ea5827f8a96c22
Author: Richard Braun <rbraun@sceen.net>
Date:   Mon Sep 3 22:19:16 2012 +0200

    Move large storage patch to pthreads

TODO: merge into ext2fs_large_stores.patch.

Index: hurd-debian/ext2fs/ext2fs.h
===================================================================
--- hurd-debian.orig/ext2fs/ext2fs.h	2012-11-26 00:24:49.000000000 +0000
+++ hurd-debian/ext2fs/ext2fs.h	2012-11-26 00:24:58.000000000 +0000
@@ -260,9 +260,9 @@
 /* Metadata about cached block. */
 extern struct disk_cache_info *disk_cache_info;
 /* Lock for these mappings */
-extern struct mutex disk_cache_lock;
+extern pthread_mutex_t disk_cache_lock;
 /* Fired when a re-association is done.  */
-extern struct condition disk_cache_reassociation;
+extern pthread_cond_t disk_cache_reassociation;
 
 void *disk_cache_block_ref (block_t block);
 void disk_cache_block_ref_ptr (void *ptr);
@@ -345,9 +345,9 @@
 boffs_ptr (off_t offset)
 {
   block_t block = boffs_block (offset);
-  mutex_lock (&disk_cache_lock);
+  pthread_mutex_lock (&disk_cache_lock);
   char *ptr = hurd_ihash_find (disk_cache_bptr, block);
-  mutex_unlock (&disk_cache_lock);
+  pthread_mutex_unlock (&disk_cache_lock);
   assert (ptr);
   ptr += offset % block_size;
   ext2_debug ("(%Ld) = %p", offset, ptr);
@@ -361,12 +361,12 @@ bptr_offs (void *ptr)
   vm_offset_t mem_offset = (char *)ptr - (char *)disk_cache;
   off_t offset;
   assert (mem_offset < disk_cache_size);
-  mutex_lock (&disk_cache_lock);
+  pthread_mutex_lock (&disk_cache_lock);
   offset = (off_t) disk_cache_info[boffs_block (mem_offset)].block
     << log2_block_size;
   assert (offset || mem_offset < block_size);
   offset += mem_offset % block_size;
-  mutex_unlock (&disk_cache_lock);
+  pthread_mutex_unlock (&disk_cache_lock);
   ext2_debug ("(%p) = %Ld", ptr, offset);
   return offset;
 }
diff --git a/ext2fs/pager.c b/ext2fs/pager.c
index 2bec88d..67c9922 100644
--- a/ext2fs/pager.c
+++ b/ext2fs/pager.c
@@ -418,7 +418,7 @@ disk_pager_read_page (vm_offset_t page, void **buf, int *writelock)
   size_t length = vm_page_size, read = 0;
   store_offset_t offset = page, dev_end = store->size;
 
-  mutex_lock (&disk_cache_lock);
+  pthread_mutex_lock (&disk_cache_lock);
   int index = offset >> log2_block_size;
   offset = ((store_offset_t) disk_cache_info[index].block << log2_block_size)
     + offset % block_size;
@@ -430,7 +430,7 @@ disk_pager_read_page (vm_offset_t page, void **buf, int *writelock)
     = disk_cache_info[index].block ^ DISK_CACHE_LAST_READ_XOR;
 #endif
   ext2_debug ("(%Ld)", offset >> log2_block_size);
-  mutex_unlock (&disk_cache_lock);
+  pthread_mutex_unlock (&disk_cache_lock);
 
   if (offset + vm_page_size > dev_end)
     length = dev_end - offset;
@@ -454,7 +454,7 @@ disk_pager_write_page (vm_offset_t page, void *buf)
   size_t length = vm_page_size, amount;
   store_offset_t offset = page, dev_end = store->size;
  
-  mutex_lock (&disk_cache_lock);
+  pthread_mutex_lock (&disk_cache_lock);
   int index = offset >> log2_block_size;
   assert (disk_cache_info[index].block != DC_NO_BLOCK);
   offset = ((store_offset_t) disk_cache_info[index].block << log2_block_size)
@@ -465,7 +465,7 @@ disk_pager_write_page (vm_offset_t page, void *buf)
   assert (disk_cache_info[index].last_read
 	  == disk_cache_info[index].block);
 #endif
-  mutex_unlock (&disk_cache_lock);
+  pthread_mutex_unlock (&disk_cache_lock);
 
   if (offset + vm_page_size > dev_end)
     length = dev_end - offset;
@@ -526,9 +526,9 @@ disk_pager_notify_evict (vm_offset_t page)
 
   ext2_debug ("(block %u)", index);
 
-  mutex_lock (&disk_cache_lock);
+  pthread_mutex_lock (&disk_cache_lock);
   disk_cache_info[index].flags &= ~DC_INCORE;
-  mutex_unlock (&disk_cache_lock);
+  pthread_mutex_unlock (&disk_cache_lock);
 }
 
 /* Satisfy a pager read request for either the disk pager or file pager
@@ -836,9 +836,9 @@
 /* Hint index for which cache block to reuse next.  */
 int disk_cache_hint;
 /* Lock for these structures.  */
-struct mutex disk_cache_lock;
+pthread_mutex_t disk_cache_lock;
 /* Fired when a re-association is done.  */
-struct condition disk_cache_reassociation;
+pthread_cond_t disk_cache_reassociation;
 
 /* Finish mapping initialization. */
 static void
@@ -848,8 +848,8 @@
     ext2_panic ("Block size %d != vm_page_size %d",
 		block_size, vm_page_size);
 
-  mutex_init (&disk_cache_lock);
-  condition_init (&disk_cache_reassociation);
+  pthread_mutex_init (&disk_cache_lock, NULL);
+  pthread_cond_init (&disk_cache_reassociation, NULL);
 
   /* Allocate space for block num -> in-memory pointer mapping.  */
   if (hurd_ihash_create (&disk_cache_bptr, HURD_IHASH_NO_LOCP))
@@ -905,7 +905,7 @@
 
   /* Return unused pages that are in core.  */
   int pending_begin = -1, pending_end = -1;
-  mutex_lock (&disk_cache_lock);
+  pthread_mutex_lock (&disk_cache_lock);
   for (index = 0; index < disk_cache_blocks; index++)
     if (! (disk_cache_info[index].flags & (DC_DONT_REUSE & ~DC_INCORE))
 	&& ! disk_cache_info[index].ref_count)
@@ -916,13 +916,13 @@ disk_cache_return_unused (void)
 	    /* Return previous region, if there is such, ... */
 	    if (pending_end >= 0)
 	      {
-		mutex_unlock (&disk_cache_lock);
+		pthread_mutex_unlock (&disk_cache_lock);
 		pager_return_some (diskfs_disk_pager,
 				   pending_begin * vm_page_size,
 				   (pending_end - pending_begin)
 				   * vm_page_size,
 				   1);
-		mutex_lock (&disk_cache_lock);
+		pthread_mutex_lock (&disk_cache_lock);
 	      }
 	    /* ... and start new region.  */
 	    pending_begin = index;
@@ -930,7 +930,7 @@ disk_cache_return_unused (void)
 	pending_end = index + 1;
       }
 
-  mutex_unlock (&disk_cache_lock);
+  pthread_mutex_unlock (&disk_cache_lock);
 
   /* Return last region, if there is such.   */
   if (pending_end >= 0)
@@ -958,7 +958,7 @@ disk_cache_block_ref (block_t block)
 
   ext2_debug ("(%u)", block);
 
-  mutex_lock (&disk_cache_lock);
+  pthread_mutex_lock (&disk_cache_lock);
 
   bptr = hurd_ihash_find (disk_cache_bptr, block);
   if (bptr)
@@ -971,8 +971,8 @@
       if (disk_cache_info[index].flags & DC_UNTOUCHED)
 	{
 	  /* Wait re-association to finish.  */
-	  condition_wait (&disk_cache_reassociation, &disk_cache_lock);
-	  mutex_unlock (&disk_cache_lock);
+	  pthread_cond_wait (&disk_cache_reassociation, &disk_cache_lock);
+	  pthread_mutex_unlock (&disk_cache_lock);
 
 #if 0
 	  printf ("Re-association -- wait finished.\n");
@@ -992,7 +992,7 @@
 		  disk_cache_info[index].ref_count,
 		  disk_cache_info[index].flags, bptr);
 
-      mutex_unlock (&disk_cache_lock);
+      pthread_mutex_unlock (&disk_cache_lock);
 
       return bptr;
     }
@@ -1030,7 +1030,7 @@ disk_cache_block_ref (block_t block)
     {
       ext2_debug ("flush %u -> %d", disk_cache_info[index].block, index);
 
-      mutex_unlock (&disk_cache_lock);
+      pthread_mutex_unlock (&disk_cache_lock);
 
       disk_cache_return_unused ();
 
@@ -1050,9 +1050,9 @@ disk_cache_block_ref (block_t block)
 
 #if 0 /* XXX: Let's see if this is needed at all.  */
 
-  mutex_unlock (&disk_cache_lock);
+  pthread_mutex_unlock (&disk_cache_lock);
   pager_return_some (diskfs_disk_pager, bptr - disk_cache, vm_page_size, 1);
-  mutex_lock (&disk_cache_lock);
+  pthread_mutex_lock (&disk_cache_lock);
 
   /* Has someone used our bptr?  Has someone mapped requested block
      while we have unlocked disk_cache_lock?  If so, environment has
@@ -1060,7 +1060,7 @@ disk_cache_block_ref (block_t block)
   if ((! (disk_cache_info[index].flags & DC_UNTOUCHED))
       || hurd_ihash_find (disk_cache_bptr, block))
     {
-      mutex_unlock (&disk_cache_lock);
+      pthread_mutex_unlock (&disk_cache_lock);
       return disk_cache_block_ref (block); /* tail recursion */
     }
 
@@ -1068,15 +1068,15 @@ disk_cache_block_ref (block_t block)
 
   /* XXX: Use libpager internals.  */
   
-  mutex_lock (&diskfs_disk_pager->interlock);
+  pthread_mutex_lock (&diskfs_disk_pager->interlock);
   int page = (bptr - disk_cache) / vm_page_size;
   assert (page >= 0);
   int is_incore = (page < diskfs_disk_pager->pagemapsize
 		   && (diskfs_disk_pager->pagemap[page] & PM_INCORE));
-  mutex_unlock (&diskfs_disk_pager->interlock);
+  pthread_mutex_unlock (&diskfs_disk_pager->interlock);
   if (is_incore)
     {
-      mutex_unlock (&disk_cache_lock);
+      pthread_mutex_unlock (&disk_cache_lock);
       printf ("INCORE\n");
       return disk_cache_block_ref (block); /* tail recursion */
     }
@@ -1096,13 +1096,13 @@ disk_cache_block_ref (block_t block)
   disk_cache_info[index].ref_count = 1;
 
   /* All data structures are set up.  */
-  mutex_unlock (&disk_cache_lock);
+  pthread_mutex_unlock (&disk_cache_lock);
 
   /* Try to read page.  */
   *(volatile char *) bptr;
 
   /* Check if it's actually read.  */
-  mutex_lock (&disk_cache_lock);
+  pthread_mutex_lock (&disk_cache_lock);
   if (disk_cache_info[index].flags & DC_UNTOUCHED)
     /* It's not read.  */
     {
@@ -1111,7 +1111,7 @@ disk_cache_block_ref (block_t block)
       disk_cache_info[index].block = DC_NO_BLOCK;
       disk_cache_info[index].flags &=~ DC_UNTOUCHED;
       disk_cache_info[index].ref_count = 0;
-      mutex_unlock (&disk_cache_lock);
+      pthread_mutex_unlock (&disk_cache_lock);
 
       /* Prepare next time association of this page to succeed.  */
       pager_flush_some (diskfs_disk_pager, bptr - disk_cache,
@@ -1124,10 +1124,10 @@ disk_cache_block_ref (block_t block)
       /* Try again.  */
       return disk_cache_block_ref (block); /* tail recursion */
     }
-  mutex_unlock (&disk_cache_lock);
+  pthread_mutex_unlock (&disk_cache_lock);
 
   /* Re-association was successful.  */
-  condition_broadcast (&disk_cache_reassociation);
+  pthread_cond_broadcast (&disk_cache_reassociation);
 
   ext2_debug ("(%u) = %p", block, bptr);
   return bptr;
@@ -1139,7 +1139,7 @@
 {
   int index;
 
-  mutex_lock (&disk_cache_lock);
+  pthread_mutex_lock (&disk_cache_lock);
   index = bptr_index (ptr);
   assert (disk_cache_info[index].ref_count >= 1);
   assert (disk_cache_info[index].ref_count + 1
@@ -1149,7 +1149,7 @@ disk_cache_block_ref_ptr (void *ptr)
 	      ptr,
 	      disk_cache_info[index].ref_count,
 	      disk_cache_info[index].flags);
-  mutex_unlock (&disk_cache_lock);
+  pthread_mutex_unlock (&disk_cache_lock);
 }
 
 void
@@ -1159,7 +1159,7 @@ disk_cache_block_deref (void *ptr)
 
   assert (disk_cache <= ptr && ptr <= disk_cache + disk_cache_size);
 
-  mutex_lock (&disk_cache_lock);
+  pthread_mutex_lock (&disk_cache_lock);
   index = bptr_index (ptr);
   ext2_debug ("(%p) (ref_count = %d, flags = 0x%x)",
 	      ptr,
@@ -1168,7 +1168,7 @@ disk_cache_block_deref (void *ptr)
   assert (! (disk_cache_info[index].flags & DC_UNTOUCHED));
   assert (disk_cache_info[index].ref_count >= 1);
   disk_cache_info[index].ref_count--;
-  mutex_unlock (&disk_cache_lock);
+  pthread_mutex_unlock (&disk_cache_lock);
 }
 
 /* Not used.  */
@@ -1179,13 +1179,13 @@ disk_cache_block_is_ref (block_t block)
   int ref;
   void *ptr;
 
-  mutex_lock (&disk_cache_lock);
+  pthread_mutex_lock (&disk_cache_lock);
   ptr = hurd_ihash_find (disk_cache_bptr, block);
   if (! ptr)
     ref = 0;
   else				/* XXX: Should check for DC_UNTOUCHED too.  */
     ref = disk_cache_info[bptr_index (ptr)].ref_count;
-  mutex_unlock (&disk_cache_lock);
+  pthread_mutex_unlock (&disk_cache_lock);
 
   return ref;
 }
diff --git a/libpager/data-return.c b/libpager/data-return.c
index 24533e7..0d71db7 100644
--- a/libpager/data-return.c
+++ b/libpager/data-return.c
@@ -243,9 +243,9 @@ _pager_do_write_request (mach_port_t object,
 	  /* Clear any error that is left.  Notification on eviction
 	     is used only to change association of page, so any
 	     error may no longer be valid.  */
- 	  mutex_lock (&p->interlock);
+ 	  pthread_mutex_lock (&p->interlock);
 	  *pm_entry = SET_PM_ERROR (SET_PM_NEXTERROR (*pm_entry, 0), 0);
- 	  mutex_unlock (&p->interlock);
+ 	  pthread_mutex_unlock (&p->interlock);
 	}
     }