iinfo.c 2.71 KB
Newer Older
J. R. Okajima's avatar
J. R. Okajima committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (C) 2005-2019 Junjiro R. Okajima
 */

/*
 * inode private data
 */

#include "aufs.h"

struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
{
	struct inode *h_inode;
	struct au_hinode *hinode;

J. R. Okajima's avatar
J. R. Okajima committed
17
18
	IiMustAnyLock(inode);

J. R. Okajima's avatar
J. R. Okajima committed
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
	hinode = au_hinode(au_ii(inode), bindex);
	h_inode = hinode->hi_inode;
	AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
	return h_inode;
}

/* todo: hard/soft set? */
void au_hiput(struct au_hinode *hinode)
{
	iput(hinode->hi_inode);
}

void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
		   struct inode *h_inode, unsigned int flags)
{
	struct au_hinode *hinode;
	struct inode *hi;
	struct au_iinfo *iinfo = au_ii(inode);

J. R. Okajima's avatar
J. R. Okajima committed
38
39
	IiMustWriteLock(inode);

J. R. Okajima's avatar
J. R. Okajima committed
40
41
42
43
44
45
46
47
48
49
50
	hinode = au_hinode(iinfo, bindex);
	hi = hinode->hi_inode;
	AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);

	if (hi)
		au_hiput(hinode);
	hinode->hi_inode = h_inode;
	if (h_inode) {
		AuDebugOn(inode->i_mode
			  && (h_inode->i_mode & S_IFMT)
			  != (inode->i_mode & S_IFMT));
J. R. Okajima's avatar
J. R. Okajima committed
51
52
		if (bindex == iinfo->ii_btop)
			au_cpup_igen(inode, h_inode);
J. R. Okajima's avatar
J. R. Okajima committed
53
54
55
	}
}

J. R. Okajima's avatar
J. R. Okajima committed
56
57
58
59
60
61
62
63
64
65
66
67
68
69
void au_update_iigen(struct inode *inode, int half)
{
	struct au_iinfo *iinfo;
	struct au_iigen *iigen;
	unsigned int sigen;

	sigen = au_sigen(inode->i_sb);
	iinfo = au_ii(inode);
	iigen = &iinfo->ii_generation;
	spin_lock(&iigen->ig_spin);
	iigen->ig_generation = sigen;
	spin_unlock(&iigen->ig_spin);
}

J. R. Okajima's avatar
J. R. Okajima committed
70
71
72
73
74
75
76
/* ---------------------------------------------------------------------- */

void au_icntnr_init_once(void *_c)
{
	struct au_icntnr *c = _c;
	struct au_iinfo *iinfo = &c->iinfo;

J. R. Okajima's avatar
J. R. Okajima committed
77
	spin_lock_init(&iinfo->ii_generation.ig_spin);
J. R. Okajima's avatar
J. R. Okajima committed
78
	au_rw_init(&iinfo->ii_rwsem);
J. R. Okajima's avatar
J. R. Okajima committed
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
	inode_init_once(&c->vfs_inode);
}

void au_hinode_init(struct au_hinode *hinode)
{
	hinode->hi_inode = NULL;
}

int au_iinfo_init(struct inode *inode)
{
	struct au_iinfo *iinfo;
	struct super_block *sb;
	struct au_hinode *hi;
	int nbr, i;

	sb = inode->i_sb;
	iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
	nbr = 1; /* re-commit later */
	hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
	if (hi) {
		iinfo->ii_hinode = hi;
		for (i = 0; i < nbr; i++, hi++)
			au_hinode_init(hi);

J. R. Okajima's avatar
J. R. Okajima committed
103
		iinfo->ii_generation.ig_generation = au_sigen(sb);
J. R. Okajima's avatar
J. R. Okajima committed
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
		iinfo->ii_btop = -1;
		iinfo->ii_bbot = -1;
		return 0;
	}
	return -ENOMEM;
}

void au_iinfo_fin(struct inode *inode)
{
	struct au_iinfo *iinfo;
	struct au_hinode *hi;
	aufs_bindex_t bindex, bbot;

	AuDebugOn(au_is_bad_inode(inode));

	iinfo = au_ii(inode);
	bindex = iinfo->ii_btop;
	if (bindex >= 0) {
		hi = au_hinode(iinfo, bindex);
		bbot = iinfo->ii_bbot;
		while (bindex++ <= bbot) {
			if (hi->hi_inode)
				au_hiput(hi);
			hi++;
		}
	}
	au_kfree_small(iinfo->ii_hinode);
J. R. Okajima's avatar
J. R. Okajima committed
131
	AuRwDestroy(&iinfo->ii_rwsem);
J. R. Okajima's avatar
J. R. Okajima committed
132
}