Changeset 1956
- Timestamp:
- 02/28/09 16:03:24 (3 years ago)
- Files:
-
- 1 modified
-
Whitix/tags/0.2b/fs/vfs/bcache.c (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
Whitix/tags/0.2b/fs/vfs/bcache.c
r1852 r1956 41 41 DWORD cacheSize=0; 42 42 extern struct DevClass storageClass; 43 int numDirty=0;44 43 45 44 static void _BufferWait(struct Buffer* buffer); … … 188 187 static void BlockBufferRemove(struct Buffer* buff) 189 188 { 190 // WaitForBuffer(buff); /* TODO: Have a wait parameter. */ 189 DWORD flags; 190 191 191 MemFree(buff->data); 192 193 IrqSaveFlags(flags); 192 194 ListRemove(&buff->list); 195 IrqRestoreFlags(flags); 196 193 197 MemCacheFree(blockCache, buff); 194 198 } … … 210 214 /* Sleep on the request wait queue, which wakes up all waiters when EndRequest is called */ 211 215 WaitForBuffer(request->buffer); 216 212 217 return request->ioStatus; 213 218 } … … 238 243 { 239 244 /* I/O error */ 240 KePrint("BlockSendRequest: error (%d) reading %u\n", err,request->sector);245 KePrint("BlockSendRequest: error (%d) reading %u\n", err, request->sector); 241 246 err=-EIO; 242 247 } … … 269 274 270 275 if (!request) 271 return -EFAULT; 276 { 277 KePrint(KERN_ERROR "BlockSendRequest: could not build request for %u\n", buff->blockNum); 278 return -EIO; 279 } 272 280 273 281 /* Buffer should already be locked if we're coming from BlockRead */ 274 282 275 err = BlockSendRequestRaw(device, request);283 err = BlockSendRequestRaw(device, request); 276 284 277 285 MemCacheFree(requestCache, request); … … 293 301 return buff; 294 302 295 if (!(buff=BlockBufferAlloc(device, blockNum)))303 if (!(buff=BlockBufferAlloc(device, blockNum))) 296 304 return NULL; 297 305 298 306 if (BlockBufferRead(device,buff)) 299 307 { … … 328 336 { 329 337 /* Just signal that the buffer is dirty, and let BufferFlusher write it to disk in the near future as an update */ 338 330 339 if (!BitTestAndSet(&buffer->flags, BUFFER_DIRTY)) 331 numDirty++; 332 333 if (numDirty == 1) 334 { 335 if (bufferFlusher) 336 ThrResumeThread(bufferFlusher); 337 } 340 device->numDirty++; 341 342 if (bufferFlusher) 343 ThrResumeThread(bufferFlusher); 338 344 339 345 return 0; … … 346 352 struct Buffer* curr,*curr2; 347 353 DWORD i; 348 354 355 if (device->numDirty) 356 { 357 BlockSyncDevice(device); 358 WAIT_ON(&device->flushDone, !device->numDirty); 359 } 360 349 361 /* If any buffers were dirty - they would have been done by BlockWrite, 350 362 which also writes them to disk through buffer flusher. So no need … … 375 387 if (sDevice->softBlockSize == blockSize) 376 388 return 0; 377 389 378 390 /* Sync all buffers with the old size */ 379 391 BlockDeviceFreeAll(sDevice); 380 392 381 sDevice->softBlockSize=blockSize; 393 sDevice->softBlockSize = blockSize; 394 382 395 return 0; 383 396 } … … 392 405 struct Buffer* buff, *buff2; 393 406 394 // KePrint("BlockSyncDevice(%s), numDirty = %d\n", KeObjGetName(&device->device.object), numDirty); 395 407 // KePrint("BlockSyncDevice(%s), numDirty = %d\n", KeObjGetName(&device->device.object), device->numDirty); 408 409 if (device->syncing || !device->numDirty) 410 return 0; 411 412 device->syncing = 1; 413 414 again: 396 415 for (i=0; i<HASH_NUM_ENTRIES; i++) 397 416 { 398 struct ListHead* head =&device->hashLists[i];417 struct ListHead* head = &device->hashLists[i]; 399 418 400 419 /* Write all the blocks belonging to device to disk */ … … 403 422 if (BufferDirty(buff)) 404 423 { 424 // KePrint("%#X: dirty(%u), %u\n", buff, buff->blockNum, device->numDirty); 425 426 --device->numDirty; 427 BitClear(&buff->flags, BUFFER_DIRTY); 428 405 429 /* For each block, call the respective StorageDevice write function */ 406 430 DoBlockWrite(buff->device, buff); 407 --numDirty;408 BitClear(&buff->flags, BUFFER_DIRTY);431 432 // KePrint("%#X: done dirty(%u), %u\n", buff, buff->blockNum, device->numDirty); 409 433 } 434 435 if (!device->numDirty) 436 goto out; 410 437 } 411 438 } 412 439 440 out: 441 if (!device->numDirty) 442 WakeUpAll(&device->flushDone); 443 else 444 goto again; 445 446 device->syncing = 0; 413 447 return 0; 414 448 } … … 459 493 while (1) 460 494 { 461 if (!numDirty) 462 { 463 ThrSuspendThread(currThread); 464 ThrSchedule(); 465 } 495 ThrSuspendThread(currThread); 496 ThrSchedule(); 466 497 467 498 BlockSyncAll(); … … 502 533 503 534 PreemptDisable(); 504 535 505 536 ListForEachEntry(curr, head, list) 506 537 if (curr->blockNum == blockNum)
