ufs_dirhash.c (183280) | ufs_dirhash.c (184205) |
---|---|
1/*- 2 * Copyright (c) 2001, 2002 Ian Dowse. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. --- 14 unchanged lines hidden (view full) --- 23 * SUCH DAMAGE. 24 */ 25 26/* 27 * This implements a hash-based lookup scheme for UFS directories. 28 */ 29 30#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2001, 2002 Ian Dowse. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. --- 14 unchanged lines hidden (view full) --- 23 * SUCH DAMAGE. 24 */ 25 26/* 27 * This implements a hash-based lookup scheme for UFS directories. 28 */ 29 30#include <sys/cdefs.h> |
31__FBSDID("$FreeBSD: head/sys/ufs/ufs/ufs_dirhash.c 183280 2008-09-22 20:53:22Z jhb $"); | 31__FBSDID("$FreeBSD: head/sys/ufs/ufs/ufs_dirhash.c 184205 2008-10-23 15:53:51Z des $"); |
32 33#include "opt_ufs.h" 34 35#ifdef UFS_DIRHASH 36 37#include <sys/param.h> 38#include <sys/systm.h> 39#include <sys/kernel.h> --- 131 unchanged lines hidden (view full) --- 171 int error; 172 173 error = 0; 174 ndh = dh = NULL; 175 vp = ip->i_vnode; 176 for (;;) { 177 /* Racy check for i_dirhash to prefetch an dirhash structure. */ 178 if (ip->i_dirhash == NULL && ndh == NULL) { | 32 33#include "opt_ufs.h" 34 35#ifdef UFS_DIRHASH 36 37#include <sys/param.h> 38#include <sys/systm.h> 39#include <sys/kernel.h> --- 131 unchanged lines hidden (view full) --- 171 int error; 172 173 error = 0; 174 ndh = dh = NULL; 175 vp = ip->i_vnode; 176 for (;;) { 177 /* Racy check for i_dirhash to prefetch an dirhash structure. */ 178 if (ip->i_dirhash == NULL && ndh == NULL) { |
179 MALLOC(ndh, struct dirhash *, sizeof *dh, M_DIRHASH, | 179 ndh = malloc(sizeof *dh, M_DIRHASH, |
180 M_NOWAIT | M_ZERO); 181 if (ndh == NULL) 182 return (NULL); 183 refcount_init(&ndh->dh_refcount, 1); 184 sx_init(&ndh->dh_lock, "dirhash"); 185 sx_xlock(&ndh->dh_lock); 186 } 187 /* --- 184 unchanged lines hidden (view full) --- 372 dh->dh_seqopt = 0; 373 dh->dh_seqoff = 0; 374 dh->dh_score = DH_SCOREINIT; 375 376 /* 377 * Use non-blocking mallocs so that we will revert to a linear 378 * lookup on failure rather than potentially blocking forever. 379 */ | 180 M_NOWAIT | M_ZERO); 181 if (ndh == NULL) 182 return (NULL); 183 refcount_init(&ndh->dh_refcount, 1); 184 sx_init(&ndh->dh_lock, "dirhash"); 185 sx_xlock(&ndh->dh_lock); 186 } 187 /* --- 184 unchanged lines hidden (view full) --- 372 dh->dh_seqopt = 0; 373 dh->dh_seqoff = 0; 374 dh->dh_score = DH_SCOREINIT; 375 376 /* 377 * Use non-blocking mallocs so that we will revert to a linear 378 * lookup on failure rather than potentially blocking forever. 379 */ |
380 MALLOC(dh->dh_hash, doff_t **, narrays * sizeof(dh->dh_hash[0]), | 380 dh->dh_hash = malloc(narrays * sizeof(dh->dh_hash[0]), |
381 M_DIRHASH, M_NOWAIT | M_ZERO); 382 if (dh->dh_hash == NULL) 383 goto fail; | 381 M_DIRHASH, M_NOWAIT | M_ZERO); 382 if (dh->dh_hash == NULL) 383 goto fail; |
384 MALLOC(dh->dh_blkfree, u_int8_t *, nblocks * sizeof(dh->dh_blkfree[0]), | 384 dh->dh_blkfree = malloc(nblocks * sizeof(dh->dh_blkfree[0]), |
385 M_DIRHASH, M_NOWAIT); 386 if (dh->dh_blkfree == NULL) 387 goto fail; 388 for (i = 0; i < narrays; i++) { 389 if ((dh->dh_hash[i] = DIRHASH_BLKALLOC_WAITOK()) == NULL) 390 goto fail; 391 for (j = 0; j < DH_NBLKOFF; j++) 392 dh->dh_hash[i][j] = DIRHASH_EMPTY; --- 87 unchanged lines hidden (view full) --- 480 481 /* 482 * Handle partially recycled as well as fully constructed hashes. 483 */ 484 if (dh->dh_hash != NULL) { 485 for (i = 0; i < dh->dh_narrays; i++) 486 if (dh->dh_hash[i] != NULL) 487 DIRHASH_BLKFREE(dh->dh_hash[i]); | 385 M_DIRHASH, M_NOWAIT); 386 if (dh->dh_blkfree == NULL) 387 goto fail; 388 for (i = 0; i < narrays; i++) { 389 if ((dh->dh_hash[i] = DIRHASH_BLKALLOC_WAITOK()) == NULL) 390 goto fail; 391 for (j = 0; j < DH_NBLKOFF; j++) 392 dh->dh_hash[i][j] = DIRHASH_EMPTY; --- 87 unchanged lines hidden (view full) --- 480 481 /* 482 * Handle partially recycled as well as fully constructed hashes. 483 */ 484 if (dh->dh_hash != NULL) { 485 for (i = 0; i < dh->dh_narrays; i++) 486 if (dh->dh_hash[i] != NULL) 487 DIRHASH_BLKFREE(dh->dh_hash[i]); |
488 FREE(dh->dh_hash, M_DIRHASH); | 488 free(dh->dh_hash, M_DIRHASH); |
489 if (dh->dh_blkfree != NULL) | 489 if (dh->dh_blkfree != NULL) |
490 FREE(dh->dh_blkfree, M_DIRHASH); | 490 free(dh->dh_blkfree, M_DIRHASH); |
491 } 492 493 /* 494 * Drop the inode's reference to the data structure. 495 */ 496 ufsdirhash_drop(dh); 497} 498 --- 670 unchanged lines hidden (view full) --- 1169 mem = dh->dh_memreq; 1170 dh->dh_memreq = 0; 1171 1172 /* Unlock everything, free the detached memory. */ 1173 ufsdirhash_release(dh); 1174 DIRHASHLIST_UNLOCK(); 1175 for (i = 0; i < narrays; i++) 1176 DIRHASH_BLKFREE(hash[i]); | 491 } 492 493 /* 494 * Drop the inode's reference to the data structure. 495 */ 496 ufsdirhash_drop(dh); 497} 498 --- 670 unchanged lines hidden (view full) --- 1169 mem = dh->dh_memreq; 1170 dh->dh_memreq = 0; 1171 1172 /* Unlock everything, free the detached memory. */ 1173 ufsdirhash_release(dh); 1174 DIRHASHLIST_UNLOCK(); 1175 for (i = 0; i < narrays; i++) 1176 DIRHASH_BLKFREE(hash[i]); |
1177 FREE(hash, M_DIRHASH); 1178 FREE(blkfree, M_DIRHASH); | 1177 free(hash, M_DIRHASH); 1178 free(blkfree, M_DIRHASH); |
1179 1180 /* Account for the returned memory, and repeat if necessary. */ 1181 DIRHASHLIST_LOCK(); 1182 ufs_dirhashmem -= mem; 1183 dh = TAILQ_FIRST(&ufsdirhash_list); 1184 } 1185 /* Success; return with list locked. */ 1186 return (0); --- 21 unchanged lines hidden --- | 1179 1180 /* Account for the returned memory, and repeat if necessary. */ 1181 DIRHASHLIST_LOCK(); 1182 ufs_dirhashmem -= mem; 1183 dh = TAILQ_FIRST(&ufsdirhash_list); 1184 } 1185 /* Success; return with list locked. */ 1186 return (0); --- 21 unchanged lines hidden --- |