1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#include "xfs.h"
19#include "xfs_fs.h"
20#include "xfs_types.h"
21#include "xfs_log.h"
22#include "xfs_trans.h"
23#include "xfs_sb.h"
24#include "xfs_ag.h"
25#include "xfs_dir2.h"
26#include "xfs_mount.h"
27#include "xfs_bmap_btree.h"
28#include "xfs_dinode.h"
29#include "xfs_inode.h"
30#include "xfs_inode_item.h"
31#include "xfs_bmap.h"
32#include "xfs_error.h"
33#include "xfs_quota.h"
34#include "xfs_itable.h"
35#include "xfs_utils.h"
36
37
38
39
40
41
42
43
44
45
46
47
48int
49xfs_dir_ialloc(
50 xfs_trans_t **tpp,
51
52 xfs_inode_t *dp,
53
54 umode_t mode,
55 xfs_nlink_t nlink,
56 xfs_dev_t rdev,
57 prid_t prid,
58 int okalloc,
59 xfs_inode_t **ipp,
60
61 int *committed)
62
63{
64 xfs_trans_t *tp;
65 xfs_trans_t *ntp;
66 xfs_inode_t *ip;
67 xfs_buf_t *ialloc_context = NULL;
68 int code;
69 uint log_res;
70 uint log_count;
71 void *dqinfo;
72 uint tflags;
73
74 tp = *tpp;
75 ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES);
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92 code = xfs_ialloc(tp, dp, mode, nlink, rdev, prid, okalloc,
93 &ialloc_context, &ip);
94
95
96
97
98
99
100 if (code) {
101 *ipp = NULL;
102 return code;
103 }
104 if (!ialloc_context && !ip) {
105 *ipp = NULL;
106 return XFS_ERROR(ENOSPC);
107 }
108
109
110
111
112
113
114
115 if (ialloc_context) {
116
117
118
119
120
121
122
123 xfs_trans_bhold(tp, ialloc_context);
124
125
126
127
128 log_res = xfs_trans_get_log_res(tp);
129 log_count = xfs_trans_get_log_count(tp);
130
131
132
133
134
135
136 dqinfo = NULL;
137 tflags = 0;
138 if (tp->t_dqinfo) {
139 dqinfo = (void *)tp->t_dqinfo;
140 tp->t_dqinfo = NULL;
141 tflags = tp->t_flags & XFS_TRANS_DQ_DIRTY;
142 tp->t_flags &= ~(XFS_TRANS_DQ_DIRTY);
143 }
144
145 ntp = xfs_trans_dup(tp);
146 code = xfs_trans_commit(tp, 0);
147 tp = ntp;
148 if (committed != NULL) {
149 *committed = 1;
150 }
151
152
153
154
155
156 if (code) {
157 xfs_buf_relse(ialloc_context);
158 if (dqinfo) {
159 tp->t_dqinfo = dqinfo;
160 xfs_trans_free_dqinfo(tp);
161 }
162 *tpp = ntp;
163 *ipp = NULL;
164 return code;
165 }
166
167
168
169
170
171 xfs_log_ticket_put(tp->t_ticket);
172 code = xfs_trans_reserve(tp, 0, log_res, 0,
173 XFS_TRANS_PERM_LOG_RES, log_count);
174
175
176
177 if (dqinfo) {
178 tp->t_dqinfo = dqinfo;
179 tp->t_flags |= tflags;
180 }
181
182 if (code) {
183 xfs_buf_relse(ialloc_context);
184 *tpp = ntp;
185 *ipp = NULL;
186 return code;
187 }
188 xfs_trans_bjoin(tp, ialloc_context);
189
190
191
192
193
194
195 code = xfs_ialloc(tp, dp, mode, nlink, rdev, prid,
196 okalloc, &ialloc_context, &ip);
197
198
199
200
201
202 if (code) {
203 *tpp = tp;
204 *ipp = NULL;
205 return code;
206 }
207 ASSERT(!ialloc_context && ip);
208
209 } else {
210 if (committed != NULL)
211 *committed = 0;
212 }
213
214 *ipp = ip;
215 *tpp = tp;
216
217 return 0;
218}
219
220
221
222
223
224
225int
226xfs_droplink(
227 xfs_trans_t *tp,
228 xfs_inode_t *ip)
229{
230 int error;
231
232 xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG);
233
234 ASSERT (ip->i_d.di_nlink > 0);
235 ip->i_d.di_nlink--;
236 drop_nlink(VFS_I(ip));
237 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
238
239 error = 0;
240 if (ip->i_d.di_nlink == 0) {
241
242
243
244
245
246
247 error = xfs_iunlink(tp, ip);
248 }
249 return error;
250}
251
252
253
254
255
256
257
258
259void
260xfs_bump_ino_vers2(
261 xfs_trans_t *tp,
262 xfs_inode_t *ip)
263{
264 xfs_mount_t *mp;
265
266 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
267 ASSERT(ip->i_d.di_version == 1);
268
269 ip->i_d.di_version = 2;
270 ip->i_d.di_onlink = 0;
271 memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
272 mp = tp->t_mountp;
273 if (!xfs_sb_version_hasnlink(&mp->m_sb)) {
274 spin_lock(&mp->m_sb_lock);
275 if (!xfs_sb_version_hasnlink(&mp->m_sb)) {
276 xfs_sb_version_addnlink(&mp->m_sb);
277 spin_unlock(&mp->m_sb_lock);
278 xfs_mod_sb(tp, XFS_SB_VERSIONNUM);
279 } else {
280 spin_unlock(&mp->m_sb_lock);
281 }
282 }
283
284}
285
286
287
288
289int
290xfs_bumplink(
291 xfs_trans_t *tp,
292 xfs_inode_t *ip)
293{
294 xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG);
295
296 ASSERT(ip->i_d.di_nlink > 0);
297 ip->i_d.di_nlink++;
298 inc_nlink(VFS_I(ip));
299 if ((ip->i_d.di_version == 1) &&
300 (ip->i_d.di_nlink > XFS_MAXLINK_1)) {
301
302
303
304
305
306
307
308
309 xfs_bump_ino_vers2(tp, ip);
310 }
311
312 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
313 return 0;
314}
315