View | Details | Raw Unified | Return to bug 120483
Collapse All | Expand All

(-)ntfs_ihash.c (-4 / +5 lines)
Lines 40-45 Link Here
40
#include <sys/malloc.h>
40
#include <sys/malloc.h>
41
#include <sys/mount.h>
41
#include <sys/mount.h>
42
#include <sys/mutex.h>
42
#include <sys/mutex.h>
43
#include <sys/condvar.h>
43
44
44
#include <fs/ntfs/ntfs.h>
45
#include <fs/ntfs/ntfs.h>
45
#include <fs/ntfs/ntfs_inode.h>
46
#include <fs/ntfs/ntfs_inode.h>
Lines 54-60 Link Here
54
static u_long	ntfs_nthash;		/* size of hash table - 1 */
55
static u_long	ntfs_nthash;		/* size of hash table - 1 */
55
#define	NTNOHASH(device, inum)	(&ntfs_nthashtbl[(minor(device) + (inum)) & ntfs_nthash])
56
#define	NTNOHASH(device, inum)	(&ntfs_nthashtbl[(minor(device) + (inum)) & ntfs_nthash])
56
static struct mtx ntfs_nthash_mtx;
57
static struct mtx ntfs_nthash_mtx;
57
struct lock ntfs_hashlock;
58
struct mtx ntfs_hashlock_mtx;
58
59
59
/*
60
/*
60
 * Initialize inode hash table.
61
 * Initialize inode hash table.
Lines 62-70 Link Here
62
void
63
void
63
ntfs_nthashinit()
64
ntfs_nthashinit()
64
{
65
{
65
	lockinit(&ntfs_hashlock, PINOD, "ntfs_nthashlock", 0, 0);
66
	mtx_init(&ntfs_hashlock_mtx, "ntfs hashlock", NULL, MTX_DEF);
66
	ntfs_nthashtbl = hashinit(desiredvnodes, M_NTFSNTHASH, &ntfs_nthash);
67
	mtx_init(&ntfs_nthash_mtx, "ntfs nthash", NULL, MTX_DEF);
67
	mtx_init(&ntfs_nthash_mtx, "ntfs nthash", NULL, MTX_DEF);
68
	ntfs_nthashtbl = hashinit(desiredvnodes, M_NTFSNTHASH, &ntfs_nthash);
68
}
69
}
69
70
70
/*
71
/*
Lines 74-80 Link Here
74
ntfs_nthashdestroy(void)
75
ntfs_nthashdestroy(void)
75
{
76
{
76
	hashdestroy(ntfs_nthashtbl, M_NTFSNTHASH, ntfs_nthash);
77
	hashdestroy(ntfs_nthashtbl, M_NTFSNTHASH, ntfs_nthash);
77
	lockdestroy(&ntfs_hashlock);
78
	mtx_destroy(&ntfs_hashlock_mtx);
78
	mtx_destroy(&ntfs_nthash_mtx);
79
	mtx_destroy(&ntfs_nthash_mtx);
79
}
80
}
80
81
(-)ntfs_ihash.h (-1 / +1 lines)
Lines 28-34 Link Here
28
 * $FreeBSD: src/sys/fs/ntfs/ntfs_ihash.h,v 1.8 2004/06/16 09:47:04 phk Exp $
28
 * $FreeBSD: src/sys/fs/ntfs/ntfs_ihash.h,v 1.8 2004/06/16 09:47:04 phk Exp $
29
 */
29
 */
30
30
31
extern struct lock ntfs_hashlock;
31
extern struct mtx ntfs_hashlock_mtx;
32
void ntfs_nthashinit(void);
32
void ntfs_nthashinit(void);
33
void ntfs_nthashdestroy(void);
33
void ntfs_nthashdestroy(void);
34
struct ntnode   *ntfs_nthashlookup(struct cdev *, ino_t);
34
struct ntnode   *ntfs_nthashlookup(struct cdev *, ino_t);
(-)ntfs_inode.h (-1 / +2 lines)
Lines 53-61 Link Here
53
	u_int32_t       i_flag;
53
	u_int32_t       i_flag;
54
54
55
	/* locking */
55
	/* locking */
56
	struct lock	i_lock;
56
	struct cv	i_lock;
57
	struct mtx	i_interlock;
57
	struct mtx	i_interlock;
58
	int		i_usecount;
58
	int		i_usecount;
59
	int		i_busy;
59
60
60
	LIST_HEAD(,fnode)	i_fnlist;
61
	LIST_HEAD(,fnode)	i_fnlist;
61
	LIST_HEAD(,ntvattr)	i_valist;
62
	LIST_HEAD(,ntvattr)	i_valist;
(-)ntfs_subr.c (-39 / +55 lines)
Lines 32-37 Link Here
32
#include <sys/types.h>
32
#include <sys/types.h>
33
#include <sys/systm.h>
33
#include <sys/systm.h>
34
#include <sys/namei.h>
34
#include <sys/namei.h>
35
#include <sys/proc.h>
35
#include <sys/kernel.h>
36
#include <sys/kernel.h>
36
#include <sys/vnode.h>
37
#include <sys/vnode.h>
37
#include <sys/mount.h>
38
#include <sys/mount.h>
Lines 41-46 Link Here
41
#include <sys/malloc.h>
42
#include <sys/malloc.h>
42
#include <sys/lock.h>
43
#include <sys/lock.h>
43
#include <sys/iconv.h>
44
#include <sys/iconv.h>
45
#include <sys/condvar.h>
46
#include <sys/sx.h>
44
47
45
/* #define NTFS_DEBUG 1 */
48
/* #define NTFS_DEBUG 1 */
46
#include <fs/ntfs/ntfs.h>
49
#include <fs/ntfs/ntfs.h>
Lines 65-71 Link Here
65
 * ntfs mount, freed upon last ntfs umount */
68
 * ntfs mount, freed upon last ntfs umount */
66
static wchar *ntfs_toupper_tab;
69
static wchar *ntfs_toupper_tab;
67
#define NTFS_TOUPPER(ch)	(ntfs_toupper_tab[(ch)])
70
#define NTFS_TOUPPER(ch)	(ntfs_toupper_tab[(ch)])
68
static struct lock ntfs_toupper_lock;
71
static struct sx ntfs_toupper_lock_sx;
69
static signed int ntfs_toupper_usecount;
72
static signed int ntfs_toupper_usecount;
70
73
71
struct iconv_functions *ntfs_iconv = NULL;
74
struct iconv_functions *ntfs_iconv = NULL;
Lines 358-364 Link Here
358
361
359
	mtx_lock(&ip->i_interlock);
362
	mtx_lock(&ip->i_interlock);
360
	ip->i_usecount++;
363
	ip->i_usecount++;
361
	lockmgr(&ip->i_lock, LK_EXCLUSIVE | LK_INTERLOCK, &ip->i_interlock);
364
	while (ip->i_busy != 0) {
365
		cv_wait(&ip->i_lock, &ip->i_interlock);
366
	}
367
	ip->i_busy = 1;
368
	mtx_unlock(&ip->i_interlock);
362
369
363
	return 0;
370
	return 0;
364
}
371
}
Lines 380-400 Link Here
380
387
381
	dprintf(("ntfs_ntlookup: looking for ntnode %d\n", ino));
388
	dprintf(("ntfs_ntlookup: looking for ntnode %d\n", ino));
382
389
383
	do {
390
	*ipp = ntfs_nthashlookup(ntmp->ntm_devvp->v_rdev, ino);
384
		ip = ntfs_nthashlookup(ntmp->ntm_devvp->v_rdev, ino);
391
	if (*ipp != NULL) {
385
		if (ip != NULL) {
392
		ntfs_ntget(*ipp);
386
			ntfs_ntget(ip);
393
		dprintf(("ntfs_ntlookup: ntnode %d: %p, usecount: %d\n",
387
			dprintf(("ntfs_ntlookup: ntnode %d: %p, usecount: %d\n",
394
			ino, ipp, (*ipp)->i_usecount));
388
				ino, ip, ip->i_usecount));
395
		return (0);
389
			*ipp = ip;
396
	}
390
			return (0);
391
		}
392
	} while (lockmgr(&ntfs_hashlock, LK_EXCLUSIVE | LK_SLEEPFAIL, NULL));
393
397
394
	MALLOC(ip, struct ntnode *, sizeof(struct ntnode), M_NTFSNTNODE,
398
	MALLOC(ip, struct ntnode *, sizeof(struct ntnode), M_NTFSNTNODE,
395
		M_WAITOK | M_ZERO);
399
		M_WAITOK | M_ZERO);
396
	ddprintf(("ntfs_ntlookup: allocating ntnode: %d: %p\n", ino, ip));
400
	ddprintf(("ntfs_ntlookup: allocating ntnode: %d: %p\n", ino, ip));
397
401
402
	mtx_lock(&ntfs_hashlock_mtx);
403
	*ipp = ntfs_nthashlookup(ntmp->ntm_devvp->v_rdev, ino);
404
	if (*ipp != NULL) {
405
		mtx_unlock(&ntfs_hashlock_mtx);
406
		ntfs_ntget(*ipp);
407
		FREE(ip, M_NTFSNTNODE);
408
		dprintf(("ntfs_ntlookup: ntnode %d: %p, usecount: %d\n",
409
			ino, ipp, (*ipp)->i_usecount));
410
		return (0);
411
	}
412
398
	/* Generic initialization */
413
	/* Generic initialization */
399
	ip->i_devvp = ntmp->ntm_devvp;
414
	ip->i_devvp = ntmp->ntm_devvp;
400
	ip->i_dev = ntmp->ntm_devvp->v_rdev;
415
	ip->i_dev = ntmp->ntm_devvp->v_rdev;
Lines 405-417 Link Here
405
	VREF(ip->i_devvp);
420
	VREF(ip->i_devvp);
406
421
407
	/* init lock and lock the newborn ntnode */
422
	/* init lock and lock the newborn ntnode */
408
	lockinit(&ip->i_lock, PINOD, "ntnode", 0, LK_EXCLUSIVE);
423
	cv_init(&ip->i_lock, "ntfslk");
409
	mtx_init(&ip->i_interlock, "ntnode interlock", NULL, MTX_DEF);
424
	mtx_init(&ip->i_interlock, "ntnode interlock", NULL, MTX_DEF);
410
	ntfs_ntget(ip);
425
	ntfs_ntget(ip);
411
426
412
	ntfs_nthashins(ip);
427
	ntfs_nthashins(ip);
413
428
414
	lockmgr(&ntfs_hashlock, LK_RELEASE, NULL);
429
	mtx_unlock(&ntfs_hashlock_mtx);
415
430
416
	*ipp = ip;
431
	*ipp = ip;
417
432
Lines 446-472 Link Here
446
	}
461
	}
447
#endif
462
#endif
448
463
449
	if (ip->i_usecount > 0) {
464
	ip->i_busy = 0;
450
		lockmgr(&ip->i_lock, LK_RELEASE|LK_INTERLOCK, &ip->i_interlock);
465
	cv_signal(&ip->i_lock);
451
		return;
466
	mtx_unlock(&ip->i_interlock);
452
	}
453
454
	dprintf(("ntfs_ntput: deallocating ntnode: %d\n", ip->i_number));
455
456
	if (LIST_FIRST(&ip->i_fnlist))
457
		panic("ntfs_ntput: ntnode has fnodes\n");
458
459
	ntfs_nthashrem(ip);
460
467
461
	while ((vap = LIST_FIRST(&ip->i_valist)) != NULL) {
468
	if (ip->i_usecount == 0) {
462
		LIST_REMOVE(vap,va_list);
469
		dprintf(("ntfs_ntput: deallocating ntnode: %d\n",
463
		ntfs_freentvattr(vap);
470
			 ip->i_number));
471
472
		if (LIST_FIRST(&ip->i_fnlist))
473
			panic("ntfs_ntput: ntnode has fnodes\n");
474
475
		ntfs_nthashrem(ip);
476
477
		while ((vap = LIST_FIRST(&ip->i_valist)) != NULL) {
478
			LIST_REMOVE(vap,va_list);
479
			ntfs_freentvattr(vap);
480
		}
481
		mtx_destroy(&ip->i_interlock);
482
		cv_destroy(&ip->i_lock);
483
		vrele(ip->i_devvp);
484
		FREE(ip, M_NTFSNTNODE);
464
	}
485
	}
465
	mtx_unlock(&ip->i_interlock);
466
	mtx_destroy(&ip->i_interlock);
467
	lockdestroy(&ip->i_lock);
468
	vrele(ip->i_devvp);
469
	FREE(ip, M_NTFSNTNODE);
470
}
486
}
471
487
472
/*
488
/*
Lines 1955-1961 Link Here
1955
ntfs_toupper_init()
1971
ntfs_toupper_init()
1956
{
1972
{
1957
	ntfs_toupper_tab = (wchar *) NULL;
1973
	ntfs_toupper_tab = (wchar *) NULL;
1958
	lockinit(&ntfs_toupper_lock, PVFS, "ntfs_toupper", 0, 0);
1974
	sx_init(&ntfs_toupper_lock_sx, "ntfs toupper lock");
1959
	ntfs_toupper_usecount = 0;
1975
	ntfs_toupper_usecount = 0;
1960
}
1976
}
1961
1977
Lines 1963-1969 Link Here
1963
ntfs_toupper_destroy(void)
1979
ntfs_toupper_destroy(void)
1964
{
1980
{
1965
1981
1966
	lockdestroy(&ntfs_toupper_lock);
1982
       sx_destroy(&ntfs_toupper_lock_sx);
1967
}
1983
}
1968
1984
1969
/*
1985
/*
Lines 1979-1985 Link Here
1979
	struct vnode *vp;
1995
	struct vnode *vp;
1980
1996
1981
	/* get exclusive access */
1997
	/* get exclusive access */
1982
	lockmgr(&ntfs_toupper_lock, LK_EXCLUSIVE, NULL);
1998
	sx_xlock(&ntfs_toupper_lock_sx);
1983
	
1999
	
1984
	/* only read the translation data from a file if it hasn't been
2000
	/* only read the translation data from a file if it hasn't been
1985
	 * read already */
2001
	 * read already */
Lines 2002-2008 Link Here
2002
2018
2003
    out:
2019
    out:
2004
	ntfs_toupper_usecount++;
2020
	ntfs_toupper_usecount++;
2005
	lockmgr(&ntfs_toupper_lock, LK_RELEASE, NULL);
2021
	sx_xunlock(&ntfs_toupper_lock_sx);
2006
	return (error);
2022
	return (error);
2007
}
2023
}
2008
2024
Lines 2014-2020 Link Here
2014
ntfs_toupper_unuse()
2030
ntfs_toupper_unuse()
2015
{
2031
{
2016
	/* get exclusive access */
2032
	/* get exclusive access */
2017
	lockmgr(&ntfs_toupper_lock, LK_EXCLUSIVE, NULL);
2033
	sx_xlock(&ntfs_toupper_lock_sx);
2018
2034
2019
	ntfs_toupper_usecount--;
2035
	ntfs_toupper_usecount--;
2020
	if (ntfs_toupper_usecount == 0) {
2036
	if (ntfs_toupper_usecount == 0) {
Lines 2029-2035 Link Here
2029
#endif
2045
#endif
2030
	
2046
	
2031
	/* release the lock */
2047
	/* release the lock */
2032
	lockmgr(&ntfs_toupper_lock, LK_RELEASE, NULL);
2048
	sx_xunlock(&ntfs_toupper_lock_sx);
2033
} 
2049
} 
2034
2050
2035
int
2051
int
(-)ntfs_vfsops.c (+1 lines)
Lines 43-48 Link Here
43
#include <sys/malloc.h>
43
#include <sys/malloc.h>
44
#include <sys/stat.h>
44
#include <sys/stat.h>
45
#include <sys/systm.h>
45
#include <sys/systm.h>
46
#include <sys/condvar.h>
46
47
47
#include <geom/geom.h>
48
#include <geom/geom.h>
48
#include <geom/geom_vfs.h>
49
#include <geom/geom_vfs.h>
(-)ntfs_vnops.c (+1 lines)
Lines 48-53 Link Here
48
#include <sys/bio.h>
48
#include <sys/bio.h>
49
#include <sys/buf.h>
49
#include <sys/buf.h>
50
#include <sys/dirent.h>
50
#include <sys/dirent.h>
51
#include <sys/condvar.h>
51
52
52
#include <vm/vm.h>
53
#include <vm/vm.h>
53
#include <vm/vm_param.h>
54
#include <vm/vm_param.h>

Return to bug 120483