[GFS2] Fix a ref count bug and other clean ups
[deliverable/linux.git] / fs / gfs2 / dir.c
CommitLineData
b3b94faa
DT
1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
4 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
7 * of the GNU General Public License v.2.
8 */
9
10/*
11* Implements Extendible Hashing as described in:
12* "Extendible Hashing" by Fagin, et al in
13* __ACM Trans. on Database Systems__, Sept 1979.
14*
15*
16* Here's the layout of dirents which is essentially the same as that of ext2
17* within a single block. The field de_name_len is the number of bytes
18* actually required for the name (no null terminator). The field de_rec_len
19* is the number of bytes allocated to the dirent. The offset of the next
20* dirent in the block is (dirent + dirent->de_rec_len). When a dirent is
21* deleted, the preceding dirent inherits its allocated space, ie
22* prev->de_rec_len += deleted->de_rec_len. Since the next dirent is obtained
23* by adding de_rec_len to the current dirent, this essentially causes the
24* deleted dirent to get jumped over when iterating through all the dirents.
25*
26* When deleting the first dirent in a block, there is no previous dirent so
27* the field de_ino is set to zero to designate it as deleted. When allocating
28* a dirent, gfs2_dirent_alloc iterates through the dirents in a block. If the
29* first dirent has (de_ino == 0) and de_rec_len is large enough, this first
30* dirent is allocated. Otherwise it must go through all the 'used' dirents
31* searching for one in which the amount of total space minus the amount of
32* used space will provide enough space for the new dirent.
33*
34* There are two types of blocks in which dirents reside. In a stuffed dinode,
35* the dirents begin at offset sizeof(struct gfs2_dinode) from the beginning of
36* the block. In leaves, they begin at offset sizeof(struct gfs2_leaf) from the
37* beginning of the leaf block. The dirents reside in leaves when
38*
39* dip->i_di.di_flags & GFS2_DIF_EXHASH is true
40*
41* Otherwise, the dirents are "linear", within a single stuffed dinode block.
42*
43* When the dirents are in leaves, the actual contents of the directory file are
44* used as an array of 64-bit block pointers pointing to the leaf blocks. The
45* dirents are NOT in the directory file itself. There can be more than one block
46* pointer in the array that points to the same leaf. In fact, when a directory
47* is first converted from linear to exhash, all of the pointers point to the
48* same leaf.
49*
50* When a leaf is completely full, the size of the hash table can be
51* doubled unless it is already at the maximum size which is hard coded into
52* GFS2_DIR_MAX_DEPTH. After that, leaves are chained together in a linked list,
53* but never before the maximum hash table size has been reached.
54*/
55
56#include <linux/sched.h>
57#include <linux/slab.h>
58#include <linux/spinlock.h>
59#include <linux/completion.h>
60#include <linux/buffer_head.h>
61#include <linux/sort.h>
5c676f6d 62#include <linux/gfs2_ondisk.h>
71b86f56 63#include <linux/crc32.h>
b3b94faa
DT
64#include <asm/semaphore.h>
65
66#include "gfs2.h"
5c676f6d
SW
67#include "lm_interface.h"
68#include "incore.h"
b3b94faa
DT
69#include "dir.h"
70#include "glock.h"
71#include "inode.h"
b3b94faa
DT
72#include "meta_io.h"
73#include "quota.h"
74#include "rgrp.h"
75#include "trans.h"
e13940ba 76#include "bmap.h"
5c676f6d 77#include "util.h"
b3b94faa
DT
78
79#define IS_LEAF 1 /* Hashed (leaf) directory */
80#define IS_DINODE 2 /* Linear (stuffed dinode block) directory */
81
82#if 1
83#define gfs2_disk_hash2offset(h) (((uint64_t)(h)) >> 1)
84#define gfs2_dir_offset2hash(p) ((uint32_t)(((uint64_t)(p)) << 1))
85#else
86#define gfs2_disk_hash2offset(h) (((uint64_t)(h)))
87#define gfs2_dir_offset2hash(p) ((uint32_t)(((uint64_t)(p))))
88#endif
89
90typedef int (*leaf_call_t) (struct gfs2_inode *dip,
91 uint32_t index, uint32_t len, uint64_t leaf_no,
92 void *data);
93
18ec7d5c
SW
94int gfs2_dir_get_buffer(struct gfs2_inode *ip, uint64_t block, int new,
95 struct buffer_head **bhp)
e13940ba
SW
96{
97 struct buffer_head *bh;
98 int error = 0;
99
100 if (new) {
101 bh = gfs2_meta_new(ip->i_gl, block);
102 gfs2_trans_add_bh(ip->i_gl, bh, 1);
103 gfs2_metatype_set(bh, GFS2_METATYPE_JD, GFS2_FORMAT_JD);
104 gfs2_buffer_clear_tail(bh, sizeof(struct gfs2_meta_header));
105 } else {
568f4c96
SW
106 error = gfs2_meta_read(ip->i_gl, block, DIO_START | DIO_WAIT,
107 &bh);
e13940ba
SW
108 if (error)
109 return error;
110 if (gfs2_metatype_check(ip->i_sbd, bh, GFS2_METATYPE_JD)) {
111 brelse(bh);
112 return -EIO;
113 }
114 }
115
116 *bhp = bh;
117 return 0;
118}
119
120
121
122static int gfs2_dir_write_stuffed(struct gfs2_inode *ip, const char *buf,
123 unsigned int offset, unsigned int size)
124
125{
126 struct buffer_head *dibh;
127 int error;
128
129 error = gfs2_meta_inode_buffer(ip, &dibh);
130 if (error)
131 return error;
132
133 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
c752666c 134 memcpy(dibh->b_data + offset + sizeof(struct gfs2_dinode), buf, size);
e13940ba
SW
135 if (ip->i_di.di_size < offset + size)
136 ip->i_di.di_size = offset + size;
137 ip->i_di.di_mtime = ip->i_di.di_ctime = get_seconds();
138 gfs2_dinode_out(&ip->i_di, dibh->b_data);
139
140 brelse(dibh);
141
142 return size;
143}
144
145
146
147/**
148 * gfs2_dir_write_data - Write directory information to the inode
149 * @ip: The GFS2 inode
150 * @buf: The buffer containing information to be written
151 * @offset: The file offset to start writing at
152 * @size: The amount of data to write
153 *
154 * Returns: The number of bytes correctly written or error code
155 */
156static int gfs2_dir_write_data(struct gfs2_inode *ip, const char *buf,
157 uint64_t offset, unsigned int size)
158{
159 struct gfs2_sbd *sdp = ip->i_sbd;
160 struct buffer_head *dibh;
161 uint64_t lblock, dblock;
162 uint32_t extlen = 0;
163 unsigned int o;
164 int copied = 0;
165 int error = 0;
166
167 if (!size)
168 return 0;
169
170 if (gfs2_is_stuffed(ip) &&
171 offset + size <= sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode))
568f4c96
SW
172 return gfs2_dir_write_stuffed(ip, buf, (unsigned int)offset,
173 size);
e13940ba
SW
174
175 if (gfs2_assert_warn(sdp, gfs2_is_jdata(ip)))
176 return -EINVAL;
177
178 if (gfs2_is_stuffed(ip)) {
179 error = gfs2_unstuff_dinode(ip, NULL, NULL);
180 if (error)
c752666c 181 return error;
e13940ba
SW
182 }
183
184 lblock = offset;
185 o = do_div(lblock, sdp->sd_jbsize) + sizeof(struct gfs2_meta_header);
186
187 while (copied < size) {
188 unsigned int amount;
189 struct buffer_head *bh;
190 int new;
191
192 amount = size - copied;
193 if (amount > sdp->sd_sb.sb_bsize - o)
194 amount = sdp->sd_sb.sb_bsize - o;
195
196 if (!extlen) {
197 new = 1;
568f4c96
SW
198 error = gfs2_block_map(ip, lblock, &new, &dblock,
199 &extlen);
e13940ba
SW
200 if (error)
201 goto fail;
202 error = -EIO;
203 if (gfs2_assert_withdraw(sdp, dblock))
204 goto fail;
205 }
206
568f4c96
SW
207 error = gfs2_dir_get_buffer(ip, dblock,
208 (amount == sdp->sd_jbsize) ?
209 1 : new, &bh);
e13940ba
SW
210 if (error)
211 goto fail;
212
213 gfs2_trans_add_bh(ip->i_gl, bh, 1);
214 memcpy(bh->b_data + o, buf, amount);
215 brelse(bh);
216 if (error)
217 goto fail;
218
219 copied += amount;
220 lblock++;
221 dblock++;
222 extlen--;
223
224 o = sizeof(struct gfs2_meta_header);
225 }
226
227out:
228 error = gfs2_meta_inode_buffer(ip, &dibh);
229 if (error)
230 return error;
231
232 if (ip->i_di.di_size < offset + copied)
233 ip->i_di.di_size = offset + copied;
234 ip->i_di.di_mtime = ip->i_di.di_ctime = get_seconds();
235
236 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
237 gfs2_dinode_out(&ip->i_di, dibh->b_data);
238 brelse(dibh);
239
240 return copied;
241fail:
242 if (copied)
243 goto out;
244 return error;
245}
246
247static int gfs2_dir_read_stuffed(struct gfs2_inode *ip, char *buf,
c752666c 248 unsigned int offset, unsigned int size)
e13940ba
SW
249{
250 struct buffer_head *dibh;
251 int error;
252
253 error = gfs2_meta_inode_buffer(ip, &dibh);
254 if (!error) {
255 offset += sizeof(struct gfs2_dinode);
256 memcpy(buf, dibh->b_data + offset, size);
257 brelse(dibh);
258 }
259
260 return (error) ? error : size;
261}
262
263
264/**
265 * gfs2_dir_read_data - Read a data from a directory inode
266 * @ip: The GFS2 Inode
267 * @buf: The buffer to place result into
268 * @offset: File offset to begin jdata_readng from
269 * @size: Amount of data to transfer
270 *
271 * Returns: The amount of data actually copied or the error
272 */
273static int gfs2_dir_read_data(struct gfs2_inode *ip, char *buf,
274 uint64_t offset, unsigned int size)
275{
276 struct gfs2_sbd *sdp = ip->i_sbd;
277 uint64_t lblock, dblock;
278 uint32_t extlen = 0;
279 unsigned int o;
280 int copied = 0;
281 int error = 0;
282
283 if (offset >= ip->i_di.di_size)
284 return 0;
285
286 if ((offset + size) > ip->i_di.di_size)
287 size = ip->i_di.di_size - offset;
288
289 if (!size)
290 return 0;
291
292 if (gfs2_is_stuffed(ip))
568f4c96
SW
293 return gfs2_dir_read_stuffed(ip, buf, (unsigned int)offset,
294 size);
e13940ba
SW
295
296 if (gfs2_assert_warn(sdp, gfs2_is_jdata(ip)))
297 return -EINVAL;
298
299 lblock = offset;
300 o = do_div(lblock, sdp->sd_jbsize) + sizeof(struct gfs2_meta_header);
301
302 while (copied < size) {
303 unsigned int amount;
304 struct buffer_head *bh;
305 int new;
306
307 amount = size - copied;
308 if (amount > sdp->sd_sb.sb_bsize - o)
309 amount = sdp->sd_sb.sb_bsize - o;
310
311 if (!extlen) {
312 new = 0;
568f4c96
SW
313 error = gfs2_block_map(ip, lblock, &new, &dblock,
314 &extlen);
e13940ba
SW
315 if (error)
316 goto fail;
317 }
318
319 if (extlen > 1)
320 gfs2_meta_ra(ip->i_gl, dblock, extlen);
321
322 if (dblock) {
323 error = gfs2_dir_get_buffer(ip, dblock, new, &bh);
324 if (error)
325 goto fail;
326 dblock++;
327 extlen--;
328 } else
329 bh = NULL;
330
331 memcpy(buf, bh->b_data + o, amount);
332 brelse(bh);
333 if (error)
334 goto fail;
335
336 copied += amount;
337 lblock++;
338
339 o = sizeof(struct gfs2_meta_header);
340 }
341
342 return copied;
343fail:
344 return (copied) ? copied : error;
345}
346
c752666c 347typedef int (*gfs2_dscan_t)(const struct gfs2_dirent *dent,
71b86f56
SW
348 const struct qstr *name,
349 void *opaque);
c752666c
SW
350
351static inline int __gfs2_dirent_find(const struct gfs2_dirent *dent,
352 const struct qstr *name, int ret)
353{
354 if (dent->de_inum.no_addr != 0 &&
355 be32_to_cpu(dent->de_hash) == name->hash &&
356 be16_to_cpu(dent->de_name_len) == name->len &&
357 memcmp((char *)(dent+1), name->name, name->len) == 0)
358 return ret;
359 return 0;
360}
361
362static int gfs2_dirent_find(const struct gfs2_dirent *dent,
71b86f56
SW
363 const struct qstr *name,
364 void *opaque)
c752666c
SW
365{
366 return __gfs2_dirent_find(dent, name, 1);
367}
368
369static int gfs2_dirent_prev(const struct gfs2_dirent *dent,
71b86f56
SW
370 const struct qstr *name,
371 void *opaque)
c752666c
SW
372{
373 return __gfs2_dirent_find(dent, name, 2);
374}
375
376/*
377 * name->name holds ptr to start of block.
378 * name->len holds size of block.
b3b94faa 379 */
c752666c 380static int gfs2_dirent_last(const struct gfs2_dirent *dent,
71b86f56
SW
381 const struct qstr *name,
382 void *opaque)
c752666c
SW
383{
384 const char *start = name->name;
385 const char *end = (const char *)dent + be16_to_cpu(dent->de_rec_len);
386 if (name->len == (end - start))
387 return 1;
388 return 0;
389}
b3b94faa 390
c752666c 391static int gfs2_dirent_find_space(const struct gfs2_dirent *dent,
71b86f56
SW
392 const struct qstr *name,
393 void *opaque)
b3b94faa 394{
c752666c
SW
395 unsigned required = GFS2_DIRENT_SIZE(name->len);
396 unsigned actual = GFS2_DIRENT_SIZE(be16_to_cpu(dent->de_name_len));
397 unsigned totlen = be16_to_cpu(dent->de_rec_len);
398
71b86f56
SW
399 if (!dent->de_inum.no_addr)
400 actual = GFS2_DIRENT_SIZE(0);
c752666c
SW
401 if ((totlen - actual) >= required)
402 return 1;
403 return 0;
404}
405
71b86f56
SW
406struct dirent_gather {
407 const struct gfs2_dirent **pdent;
408 unsigned offset;
409};
410
411static int gfs2_dirent_gather(const struct gfs2_dirent *dent,
412 const struct qstr *name,
413 void *opaque)
414{
415 struct dirent_gather *g = opaque;
416 if (dent->de_inum.no_addr) {
417 g->pdent[g->offset++] = dent;
418 }
419 return 0;
420}
421
c752666c
SW
422/*
423 * Other possible things to check:
424 * - Inode located within filesystem size (and on valid block)
425 * - Valid directory entry type
426 * Not sure how heavy-weight we want to make this... could also check
427 * hash is correct for example, but that would take a lot of extra time.
428 * For now the most important thing is to check that the various sizes
429 * are correct.
430 */
431static int gfs2_check_dirent(struct gfs2_dirent *dent, unsigned int offset,
432 unsigned int size, unsigned int len, int first)
433{
434 const char *msg = "gfs2_dirent too small";
435 if (unlikely(size < sizeof(struct gfs2_dirent)))
436 goto error;
437 msg = "gfs2_dirent misaligned";
438 if (unlikely(offset & 0x7))
439 goto error;
440 msg = "gfs2_dirent points beyond end of block";
441 if (unlikely(offset + size > len))
442 goto error;
443 msg = "zero inode number";
444 if (unlikely(!first && !dent->de_inum.no_addr))
445 goto error;
446 msg = "name length is greater than space in dirent";
447 if (dent->de_inum.no_addr &&
448 unlikely(sizeof(struct gfs2_dirent)+be16_to_cpu(dent->de_name_len) >
449 size))
450 goto error;
451 return 0;
452error:
453 printk(KERN_WARNING "gfs2_check_dirent: %s (%s)\n", msg,
454 first ? "first in block" : "not first in block");
455 return -EIO;
b3b94faa
DT
456}
457
71b86f56 458static int gfs2_dirent_offset(const void *buf)
c752666c 459{
71b86f56
SW
460 const struct gfs2_meta_header *h = buf;
461 int offset;
c752666c
SW
462
463 BUG_ON(buf == NULL);
c752666c 464
e3167ded 465 switch(be32_to_cpu(h->mh_type)) {
c752666c
SW
466 case GFS2_METATYPE_LF:
467 offset = sizeof(struct gfs2_leaf);
468 break;
469 case GFS2_METATYPE_DI:
470 offset = sizeof(struct gfs2_dinode);
471 break;
472 default:
473 goto wrong_type;
474 }
71b86f56
SW
475 return offset;
476wrong_type:
477 printk(KERN_WARNING "gfs2_scan_dirent: wrong block type %u\n",
e3167ded 478 be32_to_cpu(h->mh_type));
71b86f56
SW
479 return -1;
480}
481
482static struct gfs2_dirent *gfs2_dirent_scan(struct inode *inode,
483 void *buf,
484 unsigned int len, gfs2_dscan_t scan,
485 const struct qstr *name,
486 void *opaque)
487{
488 struct gfs2_dirent *dent, *prev;
489 unsigned offset;
490 unsigned size;
491 int ret = 0;
c752666c 492
71b86f56
SW
493 ret = gfs2_dirent_offset(buf);
494 if (ret < 0)
495 goto consist_inode;
496
497 offset = ret;
c752666c
SW
498 prev = NULL;
499 dent = (struct gfs2_dirent *)(buf + offset);
500 size = be16_to_cpu(dent->de_rec_len);
501 if (gfs2_check_dirent(dent, offset, size, len, 1))
502 goto consist_inode;
503 do {
71b86f56 504 ret = scan(dent, name, opaque);
c752666c
SW
505 if (ret)
506 break;
507 offset += size;
508 if (offset == len)
509 break;
510 prev = dent;
511 dent = (struct gfs2_dirent *)(buf + offset);
512 size = be16_to_cpu(dent->de_rec_len);
513 if (gfs2_check_dirent(dent, offset, size, len, 0))
514 goto consist_inode;
515 } while(1);
516
517 switch(ret) {
518 case 0:
519 return NULL;
520 case 1:
521 return dent;
522 case 2:
523 return prev ? prev : dent;
524 default:
525 BUG_ON(ret > 0);
526 return ERR_PTR(ret);
527 }
528
c752666c
SW
529consist_inode:
530 gfs2_consist_inode(inode->u.generic_ip);
531 return ERR_PTR(-EIO);
532}
533
534
b3b94faa
DT
535/**
536 * dirent_first - Return the first dirent
537 * @dip: the directory
538 * @bh: The buffer
539 * @dent: Pointer to list of dirents
540 *
541 * return first dirent whether bh points to leaf or stuffed dinode
542 *
543 * Returns: IS_LEAF, IS_DINODE, or -errno
544 */
545
546static int dirent_first(struct gfs2_inode *dip, struct buffer_head *bh,
547 struct gfs2_dirent **dent)
548{
549 struct gfs2_meta_header *h = (struct gfs2_meta_header *)bh->b_data;
550
e3167ded 551 if (be32_to_cpu(h->mh_type) == GFS2_METATYPE_LF) {
b3b94faa
DT
552 if (gfs2_meta_check(dip->i_sbd, bh))
553 return -EIO;
554 *dent = (struct gfs2_dirent *)(bh->b_data +
555 sizeof(struct gfs2_leaf));
556 return IS_LEAF;
557 } else {
558 if (gfs2_metatype_check(dip->i_sbd, bh, GFS2_METATYPE_DI))
559 return -EIO;
560 *dent = (struct gfs2_dirent *)(bh->b_data +
561 sizeof(struct gfs2_dinode));
562 return IS_DINODE;
563 }
564}
565
566/**
567 * dirent_next - Next dirent
568 * @dip: the directory
569 * @bh: The buffer
570 * @dent: Pointer to list of dirents
571 *
572 * Returns: 0 on success, error code otherwise
573 */
574
575static int dirent_next(struct gfs2_inode *dip, struct buffer_head *bh,
576 struct gfs2_dirent **dent)
577{
578 struct gfs2_dirent *tmp, *cur;
579 char *bh_end;
fc69d0d3 580 uint16_t cur_rec_len;
b3b94faa
DT
581
582 cur = *dent;
583 bh_end = bh->b_data + bh->b_size;
fc69d0d3 584 cur_rec_len = be16_to_cpu(cur->de_rec_len);
b3b94faa
DT
585
586 if ((char *)cur + cur_rec_len >= bh_end) {
587 if ((char *)cur + cur_rec_len > bh_end) {
588 gfs2_consist_inode(dip);
589 return -EIO;
590 }
591 return -ENOENT;
592 }
593
594 tmp = (struct gfs2_dirent *)((char *)cur + cur_rec_len);
595
fc69d0d3 596 if ((char *)tmp + be16_to_cpu(tmp->de_rec_len) > bh_end) {
b3b94faa
DT
597 gfs2_consist_inode(dip);
598 return -EIO;
599 }
4dd651ad
SW
600
601 if (cur_rec_len == 0) {
602 gfs2_consist_inode(dip);
603 return -EIO;
604 }
605
b3b94faa
DT
606 /* Only the first dent could ever have de_inum.no_addr == 0 */
607 if (!tmp->de_inum.no_addr) {
608 gfs2_consist_inode(dip);
609 return -EIO;
610 }
611
612 *dent = tmp;
613
614 return 0;
615}
616
617/**
618 * dirent_del - Delete a dirent
619 * @dip: The GFS2 inode
620 * @bh: The buffer
621 * @prev: The previous dirent
622 * @cur: The current dirent
623 *
624 */
625
626static void dirent_del(struct gfs2_inode *dip, struct buffer_head *bh,
627 struct gfs2_dirent *prev, struct gfs2_dirent *cur)
628{
fc69d0d3 629 uint16_t cur_rec_len, prev_rec_len;
b3b94faa
DT
630
631 if (!cur->de_inum.no_addr) {
632 gfs2_consist_inode(dip);
633 return;
634 }
635
d4e9c4c3 636 gfs2_trans_add_bh(dip->i_gl, bh, 1);
b3b94faa
DT
637
638 /* If there is no prev entry, this is the first entry in the block.
639 The de_rec_len is already as big as it needs to be. Just zero
640 out the inode number and return. */
641
642 if (!prev) {
643 cur->de_inum.no_addr = 0; /* No endianess worries */
644 return;
645 }
646
647 /* Combine this dentry with the previous one. */
648
fc69d0d3
SW
649 prev_rec_len = be16_to_cpu(prev->de_rec_len);
650 cur_rec_len = be16_to_cpu(cur->de_rec_len);
b3b94faa
DT
651
652 if ((char *)prev + prev_rec_len != (char *)cur)
653 gfs2_consist_inode(dip);
654 if ((char *)cur + cur_rec_len > bh->b_data + bh->b_size)
655 gfs2_consist_inode(dip);
656
657 prev_rec_len += cur_rec_len;
fc69d0d3 658 prev->de_rec_len = cpu_to_be16(prev_rec_len);
b3b94faa
DT
659}
660
c752666c
SW
661/*
662 * Takes a dent from which to grab space as an argument. Returns the
663 * newly created dent.
b3b94faa 664 */
c752666c
SW
665struct gfs2_dirent *gfs2_init_dirent(struct inode *inode,
666 struct gfs2_dirent *dent,
667 const struct qstr *name,
668 struct buffer_head *bh)
b3b94faa 669{
c752666c
SW
670 struct gfs2_inode *ip = inode->u.generic_ip;
671 struct gfs2_dirent *ndent;
672 unsigned offset = 0, totlen;
673
674 if (dent->de_inum.no_addr)
675 offset = GFS2_DIRENT_SIZE(be16_to_cpu(dent->de_name_len));
676 totlen = be16_to_cpu(dent->de_rec_len);
677 BUG_ON(offset + name->len > totlen);
678 gfs2_trans_add_bh(ip->i_gl, bh, 1);
679 ndent = (struct gfs2_dirent *)((char *)dent + offset);
680 dent->de_rec_len = cpu_to_be16(offset);
681 gfs2_qstr2dirent(name, totlen - offset, ndent);
682 return ndent;
b3b94faa
DT
683}
684
c752666c
SW
685static struct gfs2_dirent *gfs2_dirent_alloc(struct inode *inode,
686 struct buffer_head *bh,
687 const struct qstr *name)
b3b94faa
DT
688{
689 struct gfs2_dirent *dent;
71b86f56
SW
690 dent = gfs2_dirent_scan(inode, bh->b_data, bh->b_size,
691 gfs2_dirent_find_space, name, NULL);
c752666c
SW
692 if (!dent || IS_ERR(dent))
693 return dent;
694 return gfs2_init_dirent(inode, dent, name, bh);
b3b94faa
DT
695}
696
697static int get_leaf(struct gfs2_inode *dip, uint64_t leaf_no,
698 struct buffer_head **bhp)
699{
700 int error;
701
702 error = gfs2_meta_read(dip->i_gl, leaf_no, DIO_START | DIO_WAIT, bhp);
703 if (!error && gfs2_metatype_check(dip->i_sbd, *bhp, GFS2_METATYPE_LF))
704 error = -EIO;
705
706 return error;
707}
708
709/**
710 * get_leaf_nr - Get a leaf number associated with the index
711 * @dip: The GFS2 inode
712 * @index:
713 * @leaf_out:
714 *
715 * Returns: 0 on success, error code otherwise
716 */
717
718static int get_leaf_nr(struct gfs2_inode *dip, uint32_t index,
719 uint64_t *leaf_out)
720{
721 uint64_t leaf_no;
722 int error;
723
e13940ba 724 error = gfs2_dir_read_data(dip, (char *)&leaf_no,
b3b94faa
DT
725 index * sizeof(uint64_t),
726 sizeof(uint64_t));
727 if (error != sizeof(uint64_t))
728 return (error < 0) ? error : -EIO;
729
730 *leaf_out = be64_to_cpu(leaf_no);
731
732 return 0;
733}
734
735static int get_first_leaf(struct gfs2_inode *dip, uint32_t index,
736 struct buffer_head **bh_out)
737{
738 uint64_t leaf_no;
739 int error;
740
741 error = get_leaf_nr(dip, index, &leaf_no);
742 if (!error)
743 error = get_leaf(dip, leaf_no, bh_out);
744
745 return error;
746}
747
c752666c
SW
748static struct gfs2_dirent *gfs2_dirent_search(struct inode *inode,
749 const struct qstr *name,
750 gfs2_dscan_t scan,
751 struct buffer_head **pbh)
b3b94faa 752{
c752666c
SW
753 struct buffer_head *bh;
754 struct gfs2_dirent *dent;
755 struct gfs2_inode *ip = inode->u.generic_ip;
b3b94faa
DT
756 int error;
757
c752666c
SW
758 if (ip->i_di.di_flags & GFS2_DIF_EXHASH) {
759 struct gfs2_leaf *leaf;
760 unsigned hsize = 1 << ip->i_di.di_depth;
761 unsigned index;
762 u64 ln;
763 if (hsize * sizeof(u64) != ip->i_di.di_size) {
764 gfs2_consist_inode(ip);
765 return ERR_PTR(-EIO);
766 }
b3b94faa 767
c752666c
SW
768 index = name->hash >> (32 - ip->i_di.di_depth);
769 error = get_first_leaf(ip, index, &bh);
770 if (error)
771 return ERR_PTR(error);
772 do {
773 dent = gfs2_dirent_scan(inode, bh->b_data, bh->b_size,
71b86f56 774 scan, name, NULL);
c752666c
SW
775 if (dent)
776 goto got_dent;
777 leaf = (struct gfs2_leaf *)bh->b_data;
778 ln = be64_to_cpu(leaf->lf_next);
b3b94faa 779 brelse(bh);
c752666c
SW
780 if (!ln)
781 break;
782 error = get_leaf(ip, ln, &bh);
783 } while(!error);
b3b94faa 784
c752666c 785 return error ? ERR_PTR(error) : NULL;
b3b94faa 786 }
b3b94faa 787
c752666c
SW
788 error = gfs2_meta_inode_buffer(ip, &bh);
789 if (error)
790 return ERR_PTR(error);
71b86f56 791 dent = gfs2_dirent_scan(inode, bh->b_data, bh->b_size, scan, name, NULL);
b09e593d
SW
792 brelse(bh);
793
c752666c
SW
794got_dent:
795 *pbh = bh;
796 return dent;
797}
b3b94faa 798
c752666c
SW
799static struct gfs2_leaf *new_leaf(struct inode *inode, struct buffer_head **pbh, u16 depth)
800{
801 struct gfs2_inode *ip = inode->u.generic_ip;
802 u64 bn = gfs2_alloc_meta(ip);
803 struct buffer_head *bh = gfs2_meta_new(ip->i_gl, bn);
804 struct gfs2_leaf *leaf;
805 struct gfs2_dirent *dent;
71b86f56 806 struct qstr name = { .name = "", .len = 0, .hash = 0 };
c752666c
SW
807 if (!bh)
808 return NULL;
809 gfs2_trans_add_bh(ip->i_gl, bh, 1);
810 gfs2_metatype_set(bh, GFS2_METATYPE_LF, GFS2_FORMAT_LF);
811 leaf = (struct gfs2_leaf *)bh->b_data;
812 leaf->lf_depth = cpu_to_be16(depth);
813 leaf->lf_entries = cpu_to_be16(0);
814 leaf->lf_dirent_format = cpu_to_be16(GFS2_FORMAT_DE);
815 leaf->lf_next = cpu_to_be64(0);
816 memset(leaf->lf_reserved, 0, sizeof(leaf->lf_reserved));
817 dent = (struct gfs2_dirent *)(leaf+1);
71b86f56 818 gfs2_qstr2dirent(&name, bh->b_size - sizeof(struct gfs2_leaf), dent);
c752666c
SW
819 *pbh = bh;
820 return leaf;
b3b94faa
DT
821}
822
823/**
824 * dir_make_exhash - Convert a stuffed directory into an ExHash directory
825 * @dip: The GFS2 inode
826 *
827 * Returns: 0 on success, error code otherwise
828 */
829
c752666c 830static int dir_make_exhash(struct inode *inode)
b3b94faa 831{
c752666c 832 struct gfs2_inode *dip = inode->u.generic_ip;
b3b94faa
DT
833 struct gfs2_sbd *sdp = dip->i_sbd;
834 struct gfs2_dirent *dent;
c752666c 835 struct qstr args;
b3b94faa
DT
836 struct buffer_head *bh, *dibh;
837 struct gfs2_leaf *leaf;
838 int y;
839 uint32_t x;
840 uint64_t *lp, bn;
841 int error;
842
843 error = gfs2_meta_inode_buffer(dip, &dibh);
844 if (error)
845 return error;
846
b3b94faa
DT
847 /* Turn over a new leaf */
848
c752666c
SW
849 leaf = new_leaf(inode, &bh, 0);
850 if (!leaf)
851 return -ENOSPC;
852 bn = bh->b_blocknr;
b3b94faa
DT
853
854 gfs2_assert(sdp, dip->i_di.di_entries < (1 << 16));
b3b94faa
DT
855 leaf->lf_entries = cpu_to_be16(dip->i_di.di_entries);
856
857 /* Copy dirents */
858
859 gfs2_buffer_copy_tail(bh, sizeof(struct gfs2_leaf), dibh,
860 sizeof(struct gfs2_dinode));
861
862 /* Find last entry */
863
864 x = 0;
c752666c
SW
865 args.len = bh->b_size - sizeof(struct gfs2_dinode) +
866 sizeof(struct gfs2_leaf);
867 args.name = bh->b_data;
868 dent = gfs2_dirent_scan(dip->i_vnode, bh->b_data, bh->b_size,
71b86f56 869 gfs2_dirent_last, &args, NULL);
c752666c
SW
870 if (!dent) {
871 brelse(bh);
872 brelse(dibh);
873 return -EIO;
874 }
875 if (IS_ERR(dent)) {
876 brelse(bh);
877 brelse(dibh);
878 return PTR_ERR(dent);
b3b94faa 879 }
b3b94faa
DT
880
881 /* Adjust the last dirent's record length
882 (Remember that dent still points to the last entry.) */
883
4dd651ad 884 dent->de_rec_len = cpu_to_be16(be16_to_cpu(dent->de_rec_len) +
b3b94faa 885 sizeof(struct gfs2_dinode) -
4dd651ad 886 sizeof(struct gfs2_leaf));
b3b94faa
DT
887
888 brelse(bh);
889
890 /* We're done with the new leaf block, now setup the new
891 hash table. */
892
d4e9c4c3 893 gfs2_trans_add_bh(dip->i_gl, dibh, 1);
b3b94faa
DT
894 gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode));
895
896 lp = (uint64_t *)(dibh->b_data + sizeof(struct gfs2_dinode));
897
898 for (x = sdp->sd_hash_ptrs; x--; lp++)
899 *lp = cpu_to_be64(bn);
900
901 dip->i_di.di_size = sdp->sd_sb.sb_bsize / 2;
902 dip->i_di.di_blocks++;
903 dip->i_di.di_flags |= GFS2_DIF_EXHASH;
904 dip->i_di.di_payload_format = 0;
905
906 for (x = sdp->sd_hash_ptrs, y = -1; x; x >>= 1, y++) ;
907 dip->i_di.di_depth = y;
908
909 gfs2_dinode_out(&dip->i_di, dibh->b_data);
910
911 brelse(dibh);
912
913 return 0;
914}
915
916/**
917 * dir_split_leaf - Split a leaf block into two
918 * @dip: The GFS2 inode
919 * @index:
920 * @leaf_no:
921 *
922 * Returns: 0 on success, error code on failure
923 */
924
c752666c 925static int dir_split_leaf(struct inode *inode, const struct qstr *name)
b3b94faa 926{
c752666c 927 struct gfs2_inode *dip = inode->u.generic_ip;
b3b94faa
DT
928 struct buffer_head *nbh, *obh, *dibh;
929 struct gfs2_leaf *nleaf, *oleaf;
930 struct gfs2_dirent *dent, *prev = NULL, *next = NULL, *new;
931 uint32_t start, len, half_len, divider;
c752666c
SW
932 uint64_t bn, *lp, leaf_no;
933 uint32_t index;
b3b94faa
DT
934 int x, moved = 0;
935 int error;
936
c752666c
SW
937 index = name->hash >> (32 - dip->i_di.di_depth);
938 error = get_leaf_nr(dip, index, &leaf_no);
939 if (error)
940 return error;
b3b94faa
DT
941
942 /* Get the old leaf block */
b3b94faa
DT
943 error = get_leaf(dip, leaf_no, &obh);
944 if (error)
e90deff5 945 return error;
b3b94faa 946
b3b94faa 947 oleaf = (struct gfs2_leaf *)obh->b_data;
e90deff5
SW
948 if (dip->i_di.di_depth == be16_to_cpu(oleaf->lf_depth)) {
949 brelse(obh);
950 return 1; /* can't split */
951 }
952
953 gfs2_trans_add_bh(dip->i_gl, obh, 1);
b3b94faa 954
c752666c
SW
955 nleaf = new_leaf(inode, &nbh, be16_to_cpu(oleaf->lf_depth) + 1);
956 if (!nleaf) {
957 brelse(obh);
958 return -ENOSPC;
959 }
960 bn = nbh->b_blocknr;
b3b94faa 961
c752666c 962 /* Compute the start and len of leaf pointers in the hash table. */
b3b94faa
DT
963 len = 1 << (dip->i_di.di_depth - be16_to_cpu(oleaf->lf_depth));
964 half_len = len >> 1;
965 if (!half_len) {
e90deff5 966 printk(KERN_WARNING "di_depth %u lf_depth %u index %u\n", dip->i_di.di_depth, be16_to_cpu(oleaf->lf_depth), index);
b3b94faa
DT
967 gfs2_consist_inode(dip);
968 error = -EIO;
969 goto fail_brelse;
970 }
971
972 start = (index & ~(len - 1));
973
974 /* Change the pointers.
975 Don't bother distinguishing stuffed from non-stuffed.
976 This code is complicated enough already. */
c752666c 977 lp = kmalloc(half_len * sizeof(uint64_t), GFP_NOFS | __GFP_NOFAIL);
b3b94faa 978 /* Change the pointers */
b3b94faa
DT
979 for (x = 0; x < half_len; x++)
980 lp[x] = cpu_to_be64(bn);
981
e13940ba 982 error = gfs2_dir_write_data(dip, (char *)lp, start * sizeof(uint64_t),
71b86f56 983 half_len * sizeof(uint64_t));
b3b94faa
DT
984 if (error != half_len * sizeof(uint64_t)) {
985 if (error >= 0)
986 error = -EIO;
987 goto fail_lpfree;
988 }
989
990 kfree(lp);
991
992 /* Compute the divider */
b3b94faa
DT
993 divider = (start + half_len) << (32 - dip->i_di.di_depth);
994
995 /* Copy the entries */
b3b94faa
DT
996 dirent_first(dip, obh, &dent);
997
998 do {
999 next = dent;
1000 if (dirent_next(dip, obh, &next))
1001 next = NULL;
1002
1003 if (dent->de_inum.no_addr &&
1004 be32_to_cpu(dent->de_hash) < divider) {
c752666c
SW
1005 struct qstr str;
1006 str.name = (char*)(dent+1);
1007 str.len = be16_to_cpu(dent->de_name_len);
1008 str.hash = be32_to_cpu(dent->de_hash);
71b86f56 1009 new = gfs2_dirent_alloc(inode, nbh, &str);
c752666c
SW
1010 if (IS_ERR(new)) {
1011 error = PTR_ERR(new);
1012 break;
1013 }
b3b94faa
DT
1014
1015 new->de_inum = dent->de_inum; /* No endian worries */
b3b94faa 1016 new->de_type = dent->de_type; /* No endian worries */
c752666c 1017 nleaf->lf_entries = cpu_to_be16(be16_to_cpu(nleaf->lf_entries)+1);
b3b94faa
DT
1018
1019 dirent_del(dip, obh, prev, dent);
1020
1021 if (!oleaf->lf_entries)
1022 gfs2_consist_inode(dip);
c752666c 1023 oleaf->lf_entries = cpu_to_be16(be16_to_cpu(oleaf->lf_entries)-1);
b3b94faa
DT
1024
1025 if (!prev)
1026 prev = dent;
1027
1028 moved = 1;
c752666c 1029 } else {
b3b94faa 1030 prev = dent;
c752666c 1031 }
b3b94faa 1032 dent = next;
c752666c 1033 } while (dent);
b3b94faa 1034
c752666c 1035 oleaf->lf_depth = nleaf->lf_depth;
b3b94faa
DT
1036
1037 error = gfs2_meta_inode_buffer(dip, &dibh);
1038 if (!gfs2_assert_withdraw(dip->i_sbd, !error)) {
1039 dip->i_di.di_blocks++;
1040 gfs2_dinode_out(&dip->i_di, dibh->b_data);
1041 brelse(dibh);
1042 }
1043
1044 brelse(obh);
1045 brelse(nbh);
1046
1047 return error;
1048
e90deff5 1049fail_lpfree:
b3b94faa
DT
1050 kfree(lp);
1051
e90deff5 1052fail_brelse:
b3b94faa 1053 brelse(obh);
b3b94faa
DT
1054 brelse(nbh);
1055 return error;
1056}
1057
1058/**
1059 * dir_double_exhash - Double size of ExHash table
1060 * @dip: The GFS2 dinode
1061 *
1062 * Returns: 0 on success, error code on failure
1063 */
1064
1065static int dir_double_exhash(struct gfs2_inode *dip)
1066{
1067 struct gfs2_sbd *sdp = dip->i_sbd;
1068 struct buffer_head *dibh;
1069 uint32_t hsize;
1070 uint64_t *buf;
1071 uint64_t *from, *to;
1072 uint64_t block;
1073 int x;
1074 int error = 0;
1075
1076 hsize = 1 << dip->i_di.di_depth;
1077 if (hsize * sizeof(uint64_t) != dip->i_di.di_size) {
1078 gfs2_consist_inode(dip);
1079 return -EIO;
1080 }
1081
1082 /* Allocate both the "from" and "to" buffers in one big chunk */
1083
1084 buf = kcalloc(3, sdp->sd_hash_bsize, GFP_KERNEL | __GFP_NOFAIL);
1085
1086 for (block = dip->i_di.di_size >> sdp->sd_hash_bsize_shift; block--;) {
e13940ba 1087 error = gfs2_dir_read_data(dip, (char *)buf,
b3b94faa
DT
1088 block * sdp->sd_hash_bsize,
1089 sdp->sd_hash_bsize);
1090 if (error != sdp->sd_hash_bsize) {
1091 if (error >= 0)
1092 error = -EIO;
1093 goto fail;
1094 }
1095
1096 from = buf;
1097 to = (uint64_t *)((char *)buf + sdp->sd_hash_bsize);
1098
1099 for (x = sdp->sd_hash_ptrs; x--; from++) {
1100 *to++ = *from; /* No endianess worries */
1101 *to++ = *from;
1102 }
1103
e13940ba 1104 error = gfs2_dir_write_data(dip,
b3b94faa
DT
1105 (char *)buf + sdp->sd_hash_bsize,
1106 block * sdp->sd_sb.sb_bsize,
1107 sdp->sd_sb.sb_bsize);
1108 if (error != sdp->sd_sb.sb_bsize) {
1109 if (error >= 0)
1110 error = -EIO;
1111 goto fail;
1112 }
1113 }
1114
1115 kfree(buf);
1116
1117 error = gfs2_meta_inode_buffer(dip, &dibh);
1118 if (!gfs2_assert_withdraw(sdp, !error)) {
1119 dip->i_di.di_depth++;
1120 gfs2_dinode_out(&dip->i_di, dibh->b_data);
1121 brelse(dibh);
1122 }
1123
1124 return error;
1125
1126 fail:
1127 kfree(buf);
1128
1129 return error;
1130}
1131
1132/**
1133 * compare_dents - compare directory entries by hash value
1134 * @a: first dent
1135 * @b: second dent
1136 *
1137 * When comparing the hash entries of @a to @b:
1138 * gt: returns 1
1139 * lt: returns -1
1140 * eq: returns 0
1141 */
1142
1143static int compare_dents(const void *a, const void *b)
1144{
1145 struct gfs2_dirent *dent_a, *dent_b;
1146 uint32_t hash_a, hash_b;
1147 int ret = 0;
1148
1149 dent_a = *(struct gfs2_dirent **)a;
c752666c 1150 hash_a = be32_to_cpu(dent_a->de_hash);
b3b94faa
DT
1151
1152 dent_b = *(struct gfs2_dirent **)b;
c752666c 1153 hash_b = be32_to_cpu(dent_b->de_hash);
b3b94faa
DT
1154
1155 if (hash_a > hash_b)
1156 ret = 1;
1157 else if (hash_a < hash_b)
1158 ret = -1;
1159 else {
4dd651ad
SW
1160 unsigned int len_a = be16_to_cpu(dent_a->de_name_len);
1161 unsigned int len_b = be16_to_cpu(dent_b->de_name_len);
b3b94faa
DT
1162
1163 if (len_a > len_b)
1164 ret = 1;
1165 else if (len_a < len_b)
1166 ret = -1;
1167 else
1168 ret = memcmp((char *)(dent_a + 1),
1169 (char *)(dent_b + 1),
1170 len_a);
1171 }
1172
1173 return ret;
1174}
1175
1176/**
1177 * do_filldir_main - read out directory entries
1178 * @dip: The GFS2 inode
1179 * @offset: The offset in the file to read from
1180 * @opaque: opaque data to pass to filldir
1181 * @filldir: The function to pass entries to
1182 * @darr: an array of struct gfs2_dirent pointers to read
1183 * @entries: the number of entries in darr
1184 * @copied: pointer to int that's non-zero if a entry has been copied out
1185 *
1186 * Jump through some hoops to make sure that if there are hash collsions,
1187 * they are read out at the beginning of a buffer. We want to minimize
1188 * the possibility that they will fall into different readdir buffers or
1189 * that someone will want to seek to that location.
1190 *
1191 * Returns: errno, >0 on exception from filldir
1192 */
1193
1194static int do_filldir_main(struct gfs2_inode *dip, uint64_t *offset,
1195 void *opaque, gfs2_filldir_t filldir,
71b86f56 1196 const struct gfs2_dirent **darr, uint32_t entries,
b3b94faa
DT
1197 int *copied)
1198{
71b86f56 1199 const struct gfs2_dirent *dent, *dent_next;
b3b94faa
DT
1200 struct gfs2_inum inum;
1201 uint64_t off, off_next;
1202 unsigned int x, y;
1203 int run = 0;
1204 int error = 0;
1205
1206 sort(darr, entries, sizeof(struct gfs2_dirent *), compare_dents, NULL);
1207
1208 dent_next = darr[0];
1209 off_next = be32_to_cpu(dent_next->de_hash);
1210 off_next = gfs2_disk_hash2offset(off_next);
1211
1212 for (x = 0, y = 1; x < entries; x++, y++) {
1213 dent = dent_next;
1214 off = off_next;
1215
1216 if (y < entries) {
1217 dent_next = darr[y];
1218 off_next = be32_to_cpu(dent_next->de_hash);
1219 off_next = gfs2_disk_hash2offset(off_next);
1220
1221 if (off < *offset)
1222 continue;
1223 *offset = off;
1224
1225 if (off_next == off) {
1226 if (*copied && !run)
1227 return 1;
1228 run = 1;
1229 } else
1230 run = 0;
1231 } else {
1232 if (off < *offset)
1233 continue;
1234 *offset = off;
1235 }
1236
1237 gfs2_inum_in(&inum, (char *)&dent->de_inum);
1238
1239 error = filldir(opaque, (char *)(dent + 1),
4dd651ad 1240 be16_to_cpu(dent->de_name_len),
b3b94faa 1241 off, &inum,
4dd651ad 1242 be16_to_cpu(dent->de_type));
b3b94faa
DT
1243 if (error)
1244 return 1;
1245
1246 *copied = 1;
1247 }
1248
1249 /* Increment the *offset by one, so the next time we come into the
1250 do_filldir fxn, we get the next entry instead of the last one in the
1251 current leaf */
1252
1253 (*offset)++;
1254
1255 return 0;
1256}
1257
71b86f56
SW
1258static int gfs2_dir_read_leaf(struct inode *inode, u64 *offset, void *opaque,
1259 gfs2_filldir_t filldir, int *copied,
1260 unsigned *depth, u64 leaf_no)
b3b94faa 1261{
71b86f56
SW
1262 struct gfs2_inode *ip = inode->u.generic_ip;
1263 struct buffer_head *bh;
1264 struct gfs2_leaf *lf;
1265 unsigned entries = 0;
1266 unsigned leaves = 0;
1267 const struct gfs2_dirent **darr, *dent;
1268 struct dirent_gather g;
1269 struct buffer_head **larr;
1270 int leaf = 0;
1271 int error, i;
1272 u64 lfn = leaf_no;
b3b94faa 1273
b3b94faa 1274 do {
71b86f56 1275 error = get_leaf(ip, lfn, &bh);
b3b94faa 1276 if (error)
71b86f56
SW
1277 goto out;
1278 lf = (struct gfs2_leaf *)bh->b_data;
1279 if (leaves == 0)
1280 *depth = be16_to_cpu(lf->lf_depth);
1281 entries += be16_to_cpu(lf->lf_entries);
1282 leaves++;
1283 lfn = be64_to_cpu(lf->lf_next);
1284 brelse(bh);
1285 } while(lfn);
b3b94faa
DT
1286
1287 if (!entries)
1288 return 0;
1289
71b86f56
SW
1290 error = -ENOMEM;
1291 larr = kmalloc((leaves + entries) * sizeof(void*), GFP_KERNEL);
1292 if (!larr)
1293 goto out;
1294 darr = (const struct gfs2_dirent **)(larr + leaves);
1295 g.pdent = darr;
1296 g.offset = 0;
1297 lfn = leaf_no;
b3b94faa 1298
71b86f56
SW
1299 do {
1300 error = get_leaf(ip, lfn, &bh);
b3b94faa 1301 if (error)
71b86f56
SW
1302 goto out_kfree;
1303 lf = (struct gfs2_leaf *)bh->b_data;
1304 lfn = be64_to_cpu(lf->lf_next);
1305 if (lf->lf_entries) {
1306 dent = gfs2_dirent_scan(inode, bh->b_data, bh->b_size,
1307 gfs2_dirent_gather, NULL, &g);
1308 error = PTR_ERR(dent);
1309 if (IS_ERR(dent)) {
1310 goto out_kfree;
1311 }
1312 error = 0;
1313 larr[leaf++] = bh;
b3b94faa 1314 } else {
71b86f56 1315 brelse(bh);
b3b94faa 1316 }
71b86f56 1317 } while(lfn);
b3b94faa 1318
71b86f56 1319 error = do_filldir_main(ip, offset, opaque, filldir, darr,
b3b94faa 1320 entries, copied);
71b86f56
SW
1321out_kfree:
1322 for(i = 0; i < leaf; i++)
1323 brelse(larr[i]);
b3b94faa 1324 kfree(larr);
71b86f56 1325out:
b3b94faa
DT
1326 return error;
1327}
1328
1329/**
c752666c
SW
1330 * dir_e_read - Reads the entries from a directory into a filldir buffer
1331 * @dip: dinode pointer
1332 * @offset: the hash of the last entry read shifted to the right once
1333 * @opaque: buffer for the filldir function to fill
1334 * @filldir: points to the filldir function to use
b3b94faa 1335 *
c752666c 1336 * Returns: errno
b3b94faa
DT
1337 */
1338
71b86f56 1339static int dir_e_read(struct inode *inode, uint64_t *offset, void *opaque,
c752666c 1340 gfs2_filldir_t filldir)
b3b94faa 1341{
71b86f56 1342 struct gfs2_inode *dip = inode->u.generic_ip;
c752666c 1343 struct gfs2_sbd *sdp = dip->i_sbd;
71b86f56 1344 uint32_t hsize, len = 0;
c752666c
SW
1345 uint32_t ht_offset, lp_offset, ht_offset_cur = -1;
1346 uint32_t hash, index;
1347 uint64_t *lp;
1348 int copied = 0;
1349 int error = 0;
71b86f56 1350 unsigned depth;
b3b94faa
DT
1351
1352 hsize = 1 << dip->i_di.di_depth;
1353 if (hsize * sizeof(uint64_t) != dip->i_di.di_size) {
1354 gfs2_consist_inode(dip);
1355 return -EIO;
1356 }
1357
1358 hash = gfs2_dir_offset2hash(*offset);
1359 index = hash >> (32 - dip->i_di.di_depth);
1360
1361 lp = kmalloc(sdp->sd_hash_bsize, GFP_KERNEL);
1362 if (!lp)
1363 return -ENOMEM;
1364
1365 while (index < hsize) {
1366 lp_offset = index & (sdp->sd_hash_ptrs - 1);
1367 ht_offset = index - lp_offset;
1368
1369 if (ht_offset_cur != ht_offset) {
e13940ba 1370 error = gfs2_dir_read_data(dip, (char *)lp,
b3b94faa
DT
1371 ht_offset * sizeof(uint64_t),
1372 sdp->sd_hash_bsize);
1373 if (error != sdp->sd_hash_bsize) {
1374 if (error >= 0)
1375 error = -EIO;
1376 goto out;
1377 }
1378 ht_offset_cur = ht_offset;
1379 }
1380
71b86f56
SW
1381 error = gfs2_dir_read_leaf(inode, offset, opaque, filldir,
1382 &copied, &depth,
1383 be64_to_cpu(lp[lp_offset]));
b3b94faa 1384 if (error)
71b86f56 1385 break;
b3b94faa 1386
71b86f56 1387 len = 1 << (dip->i_di.di_depth - depth);
b3b94faa
DT
1388 index = (index & ~(len - 1)) + len;
1389 }
1390
71b86f56 1391out:
b3b94faa 1392 kfree(lp);
71b86f56
SW
1393 if (error > 0)
1394 error = 0;
b3b94faa
DT
1395 return error;
1396}
1397
71b86f56
SW
1398int gfs2_dir_read(struct inode *inode, uint64_t *offset, void *opaque,
1399 gfs2_filldir_t filldir)
b3b94faa 1400{
71b86f56
SW
1401 struct gfs2_inode *dip = inode->u.generic_ip;
1402 struct dirent_gather g;
1403 const struct gfs2_dirent **darr, *dent;
b3b94faa
DT
1404 struct buffer_head *dibh;
1405 int copied = 0;
1406 int error;
1407
71b86f56
SW
1408 if (!dip->i_di.di_entries)
1409 return 0;
1410
1411 if (dip->i_di.di_flags & GFS2_DIF_EXHASH)
1412 return dir_e_read(inode, offset, opaque, filldir);
1413
b3b94faa
DT
1414 if (!gfs2_is_stuffed(dip)) {
1415 gfs2_consist_inode(dip);
1416 return -EIO;
1417 }
1418
b3b94faa
DT
1419 error = gfs2_meta_inode_buffer(dip, &dibh);
1420 if (error)
1421 return error;
1422
71b86f56
SW
1423 error = -ENOMEM;
1424 darr = kmalloc(dip->i_di.di_entries * sizeof(struct gfs2_dirent *),
1425 GFP_KERNEL);
1426 if (darr) {
1427 g.pdent = darr;
1428 g.offset = 0;
1429 dent = gfs2_dirent_scan(inode, dibh->b_data, dibh->b_size,
1430 gfs2_dirent_gather, NULL, &g);
1431 if (IS_ERR(dent)) {
1432 error = PTR_ERR(dent);
1433 goto out;
1434 }
1435 error = do_filldir_main(dip, offset, opaque, filldir, darr,
1436 dip->i_di.di_entries, &copied);
1437out:
1438 kfree(darr);
1439 }
1440
b3b94faa
DT
1441 if (error > 0)
1442 error = 0;
1443
1444 brelse(dibh);
1445
1446 return error;
1447}
1448
b3b94faa
DT
1449/**
1450 * gfs2_dir_search - Search a directory
1451 * @dip: The GFS2 inode
1452 * @filename:
1453 * @inode:
1454 *
1455 * This routine searches a directory for a file or another directory.
1456 * Assumes a glock is held on dip.
1457 *
1458 * Returns: errno
1459 */
1460
c752666c 1461int gfs2_dir_search(struct inode *dir, const struct qstr *name,
b3b94faa
DT
1462 struct gfs2_inum *inum, unsigned int *type)
1463{
c752666c
SW
1464 struct buffer_head *bh;
1465 struct gfs2_dirent *dent;
1466
1467 dent = gfs2_dirent_search(dir, name, gfs2_dirent_find, &bh);
1468 if (dent) {
1469 if (IS_ERR(dent))
1470 return PTR_ERR(dent);
1471 if (inum)
1472 gfs2_inum_in(inum, (char *)&dent->de_inum);
1473 if (type)
1474 *type = be16_to_cpu(dent->de_type);
1475 brelse(bh);
1476 return 0;
1477 }
1478 return -ENOENT;
1479}
1480
1481static int dir_new_leaf(struct inode *inode, const struct qstr *name)
1482{
1483 struct buffer_head *bh, *obh;
1484 struct gfs2_inode *ip = inode->u.generic_ip;
1485 struct gfs2_leaf *leaf, *oleaf;
b3b94faa 1486 int error;
c752666c
SW
1487 u32 index;
1488 u64 bn;
b3b94faa 1489
c752666c
SW
1490 index = name->hash >> (32 - ip->i_di.di_depth);
1491 error = get_first_leaf(ip, index, &obh);
1492 if (error)
1493 return error;
1494 do {
1495 oleaf = (struct gfs2_leaf *)obh->b_data;
1496 bn = be64_to_cpu(oleaf->lf_next);
1497 if (!bn)
1498 break;
1499 brelse(obh);
1500 error = get_leaf(ip, bn, &obh);
1501 if (error)
1502 return error;
1503 } while(1);
b3b94faa 1504
c752666c
SW
1505 gfs2_trans_add_bh(ip->i_gl, obh, 1);
1506
1507 leaf = new_leaf(inode, &bh, be16_to_cpu(oleaf->lf_depth));
1508 if (!leaf) {
1509 brelse(obh);
1510 return -ENOSPC;
1511 }
1512 oleaf->lf_next = cpu_to_be64(bn);
1513 brelse(bh);
1514 brelse(obh);
1515
1516 error = gfs2_meta_inode_buffer(ip, &bh);
1517 if (error)
1518 return error;
1519 gfs2_trans_add_bh(ip->i_gl, bh, 1);
1520 ip->i_di.di_blocks++;
1521 gfs2_dinode_out(&ip->i_di, bh->b_data);
1522 brelse(bh);
1523 return 0;
b3b94faa
DT
1524}
1525
1526/**
1527 * gfs2_dir_add - Add new filename into directory
1528 * @dip: The GFS2 inode
1529 * @filename: The new name
1530 * @inode: The inode number of the entry
1531 * @type: The type of the entry
1532 *
1533 * Returns: 0 on success, error code on failure
1534 */
1535
c752666c
SW
1536int gfs2_dir_add(struct inode *inode, const struct qstr *name,
1537 const struct gfs2_inum *inum, unsigned type)
b3b94faa 1538{
c752666c
SW
1539 struct gfs2_inode *ip = inode->u.generic_ip;
1540 struct buffer_head *bh;
1541 struct gfs2_dirent *dent;
1542 struct gfs2_leaf *leaf;
b3b94faa
DT
1543 int error;
1544
c752666c
SW
1545 while(1) {
1546 dent = gfs2_dirent_search(inode, name, gfs2_dirent_find_space,
1547 &bh);
1548 if (dent) {
1549 if (IS_ERR(dent))
1550 return PTR_ERR(dent);
1551 dent = gfs2_init_dirent(inode, dent, name, bh);
1552 gfs2_inum_out(inum, (char *)&dent->de_inum);
1553 dent->de_type = cpu_to_be16(type);
1554 if (ip->i_di.di_flags & GFS2_DIF_EXHASH) {
1555 leaf = (struct gfs2_leaf *)bh->b_data;
1556 leaf->lf_entries = cpu_to_be16(be16_to_cpu(leaf->lf_entries) + 1);
1557 }
1558 brelse(bh);
1559 error = gfs2_meta_inode_buffer(ip, &bh);
1560 if (error)
1561 break;
1562 gfs2_trans_add_bh(ip->i_gl, bh, 1);
1563 ip->i_di.di_entries++;
1564 ip->i_di.di_mtime = ip->i_di.di_ctime = get_seconds();
1565 gfs2_dinode_out(&ip->i_di, bh->b_data);
1566 brelse(bh);
1567 error = 0;
1568 break;
1569 }
1570 if (!(ip->i_di.di_flags & GFS2_DIF_EXHASH)) {
1571 error = dir_make_exhash(inode);
1572 if (error)
1573 break;
1574 continue;
1575 }
1576 error = dir_split_leaf(inode, name);
1577 if (error == 0)
1578 continue;
e90deff5 1579 if (error < 0)
c752666c
SW
1580 break;
1581 if (ip->i_di.di_depth < GFS2_DIR_MAX_DEPTH) {
1582 error = dir_double_exhash(ip);
1583 if (error)
1584 break;
1585 error = dir_split_leaf(inode, name);
e90deff5 1586 if (error < 0)
c752666c 1587 break;
e90deff5
SW
1588 if (error == 0)
1589 continue;
c752666c
SW
1590 }
1591 error = dir_new_leaf(inode, name);
1592 if (!error)
1593 continue;
1594 error = -ENOSPC;
1595 break;
1596 }
b3b94faa
DT
1597 return error;
1598}
1599
c752666c 1600
b3b94faa
DT
1601/**
1602 * gfs2_dir_del - Delete a directory entry
1603 * @dip: The GFS2 inode
1604 * @filename: The filename
1605 *
1606 * Returns: 0 on success, error code on failure
1607 */
1608
c752666c 1609int gfs2_dir_del(struct gfs2_inode *dip, const struct qstr *name)
b3b94faa 1610{
c752666c
SW
1611 struct gfs2_dirent *dent, *prev = NULL;
1612 struct buffer_head *bh;
b3b94faa
DT
1613 int error;
1614
c752666c
SW
1615 /* Returns _either_ the entry (if its first in block) or the
1616 previous entry otherwise */
1617 dent = gfs2_dirent_search(dip->i_vnode, name, gfs2_dirent_prev, &bh);
1618 if (!dent) {
1619 gfs2_consist_inode(dip);
1620 return -EIO;
1621 }
1622 if (IS_ERR(dent)) {
1623 gfs2_consist_inode(dip);
1624 return PTR_ERR(dent);
1625 }
1626 /* If not first in block, adjust pointers accordingly */
71b86f56 1627 if (gfs2_dirent_find(dent, name, NULL) == 0) {
c752666c
SW
1628 prev = dent;
1629 dent = (struct gfs2_dirent *)((char *)dent + be16_to_cpu(prev->de_rec_len));
1630 }
1631
1632 dirent_del(dip, bh, prev, dent);
1633 if (dip->i_di.di_flags & GFS2_DIF_EXHASH) {
1634 struct gfs2_leaf *leaf = (struct gfs2_leaf *)bh->b_data;
1635 u16 entries = be16_to_cpu(leaf->lf_entries);
1636 if (!entries)
1637 gfs2_consist_inode(dip);
1638 leaf->lf_entries = cpu_to_be16(--entries);
1639 brelse(bh);
1640 }
1641
1642 error = gfs2_meta_inode_buffer(dip, &bh);
1643 if (error)
1644 return error;
1645
1646 if (!dip->i_di.di_entries)
1647 gfs2_consist_inode(dip);
1648 gfs2_trans_add_bh(dip->i_gl, bh, 1);
1649 dip->i_di.di_entries--;
1650 dip->i_di.di_mtime = dip->i_di.di_ctime = get_seconds();
1651 gfs2_dinode_out(&dip->i_di, bh->b_data);
1652 brelse(bh);
b3b94faa
DT
1653
1654 return error;
1655}
1656
b3b94faa
DT
1657/**
1658 * gfs2_dir_mvino - Change inode number of directory entry
1659 * @dip: The GFS2 inode
1660 * @filename:
1661 * @new_inode:
1662 *
1663 * This routine changes the inode number of a directory entry. It's used
1664 * by rename to change ".." when a directory is moved.
1665 * Assumes a glock is held on dvp.
1666 *
1667 * Returns: errno
1668 */
1669
c752666c 1670int gfs2_dir_mvino(struct gfs2_inode *dip, const struct qstr *filename,
b3b94faa
DT
1671 struct gfs2_inum *inum, unsigned int new_type)
1672{
c752666c
SW
1673 struct buffer_head *bh;
1674 struct gfs2_dirent *dent;
b3b94faa
DT
1675 int error;
1676
c752666c
SW
1677 dent = gfs2_dirent_search(dip->i_vnode, filename, gfs2_dirent_find, &bh);
1678 if (!dent) {
1679 gfs2_consist_inode(dip);
1680 return -EIO;
1681 }
1682 if (IS_ERR(dent))
1683 return PTR_ERR(dent);
b3b94faa 1684
c752666c
SW
1685 gfs2_trans_add_bh(dip->i_gl, bh, 1);
1686 gfs2_inum_out(inum, (char *)&dent->de_inum);
1687 dent->de_type = cpu_to_be16(new_type);
1688
1689 if (dip->i_di.di_flags & GFS2_DIF_EXHASH) {
1690 brelse(bh);
1691 error = gfs2_meta_inode_buffer(dip, &bh);
1692 if (error)
1693 return error;
1694 gfs2_trans_add_bh(dip->i_gl, bh, 1);
1695 }
1696
1697 dip->i_di.di_mtime = dip->i_di.di_ctime = get_seconds();
1698 gfs2_dinode_out(&dip->i_di, bh->b_data);
1699 brelse(bh);
1700 return 0;
b3b94faa
DT
1701}
1702
1703/**
1704 * foreach_leaf - call a function for each leaf in a directory
1705 * @dip: the directory
1706 * @lc: the function to call for each each
1707 * @data: private data to pass to it
1708 *
1709 * Returns: errno
1710 */
1711
1712static int foreach_leaf(struct gfs2_inode *dip, leaf_call_t lc, void *data)
1713{
1714 struct gfs2_sbd *sdp = dip->i_sbd;
1715 struct buffer_head *bh;
c752666c 1716 struct gfs2_leaf *leaf;
b3b94faa
DT
1717 uint32_t hsize, len;
1718 uint32_t ht_offset, lp_offset, ht_offset_cur = -1;
1719 uint32_t index = 0;
1720 uint64_t *lp;
1721 uint64_t leaf_no;
1722 int error = 0;
1723
1724 hsize = 1 << dip->i_di.di_depth;
1725 if (hsize * sizeof(uint64_t) != dip->i_di.di_size) {
1726 gfs2_consist_inode(dip);
1727 return -EIO;
1728 }
1729
1730 lp = kmalloc(sdp->sd_hash_bsize, GFP_KERNEL);
1731 if (!lp)
1732 return -ENOMEM;
1733
1734 while (index < hsize) {
1735 lp_offset = index & (sdp->sd_hash_ptrs - 1);
1736 ht_offset = index - lp_offset;
1737
1738 if (ht_offset_cur != ht_offset) {
e13940ba 1739 error = gfs2_dir_read_data(dip, (char *)lp,
b3b94faa
DT
1740 ht_offset * sizeof(uint64_t),
1741 sdp->sd_hash_bsize);
1742 if (error != sdp->sd_hash_bsize) {
1743 if (error >= 0)
1744 error = -EIO;
1745 goto out;
1746 }
1747 ht_offset_cur = ht_offset;
1748 }
1749
1750 leaf_no = be64_to_cpu(lp[lp_offset]);
1751 if (leaf_no) {
1752 error = get_leaf(dip, leaf_no, &bh);
1753 if (error)
1754 goto out;
c752666c 1755 leaf = (struct gfs2_leaf *)bh->b_data;
b3b94faa
DT
1756 brelse(bh);
1757
c752666c 1758 len = 1 << (dip->i_di.di_depth - be16_to_cpu(leaf->lf_depth));
b3b94faa
DT
1759
1760 error = lc(dip, index, len, leaf_no, data);
1761 if (error)
1762 goto out;
1763
1764 index = (index & ~(len - 1)) + len;
1765 } else
1766 index++;
1767 }
1768
1769 if (index != hsize) {
1770 gfs2_consist_inode(dip);
1771 error = -EIO;
1772 }
1773
1774 out:
1775 kfree(lp);
1776
1777 return error;
1778}
1779
1780/**
1781 * leaf_dealloc - Deallocate a directory leaf
1782 * @dip: the directory
1783 * @index: the hash table offset in the directory
1784 * @len: the number of pointers to this leaf
1785 * @leaf_no: the leaf number
1786 * @data: not used
1787 *
1788 * Returns: errno
1789 */
1790
1791static int leaf_dealloc(struct gfs2_inode *dip, uint32_t index, uint32_t len,
1792 uint64_t leaf_no, void *data)
1793{
1794 struct gfs2_sbd *sdp = dip->i_sbd;
c752666c 1795 struct gfs2_leaf *tmp_leaf;
b3b94faa
DT
1796 struct gfs2_rgrp_list rlist;
1797 struct buffer_head *bh, *dibh;
c752666c 1798 uint64_t blk, nblk;
b3b94faa
DT
1799 unsigned int rg_blocks = 0, l_blocks = 0;
1800 char *ht;
1801 unsigned int x, size = len * sizeof(uint64_t);
1802 int error;
1803
1804 memset(&rlist, 0, sizeof(struct gfs2_rgrp_list));
1805
1806 ht = kzalloc(size, GFP_KERNEL);
1807 if (!ht)
1808 return -ENOMEM;
1809
1810 gfs2_alloc_get(dip);
1811
1812 error = gfs2_quota_hold(dip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
1813 if (error)
1814 goto out;
1815
1816 error = gfs2_rindex_hold(sdp, &dip->i_alloc.al_ri_gh);
1817 if (error)
1818 goto out_qs;
1819
1820 /* Count the number of leaves */
1821
c752666c 1822 for (blk = leaf_no; blk; blk = nblk) {
b3b94faa
DT
1823 error = get_leaf(dip, blk, &bh);
1824 if (error)
1825 goto out_rlist;
c752666c
SW
1826 tmp_leaf = (struct gfs2_leaf *)bh->b_data;
1827 nblk = be64_to_cpu(tmp_leaf->lf_next);
b3b94faa
DT
1828 brelse(bh);
1829
1830 gfs2_rlist_add(sdp, &rlist, blk);
1831 l_blocks++;
1832 }
1833
1834 gfs2_rlist_alloc(&rlist, LM_ST_EXCLUSIVE, 0);
1835
1836 for (x = 0; x < rlist.rl_rgrps; x++) {
1837 struct gfs2_rgrpd *rgd;
5c676f6d 1838 rgd = rlist.rl_ghs[x].gh_gl->gl_object;
b3b94faa
DT
1839 rg_blocks += rgd->rd_ri.ri_length;
1840 }
1841
1842 error = gfs2_glock_nq_m(rlist.rl_rgrps, rlist.rl_ghs);
1843 if (error)
1844 goto out_rlist;
1845
1846 error = gfs2_trans_begin(sdp,
5c676f6d 1847 rg_blocks + (DIV_ROUND_UP(size, sdp->sd_jbsize) + 1) +
b3b94faa
DT
1848 RES_DINODE + RES_STATFS + RES_QUOTA, l_blocks);
1849 if (error)
1850 goto out_rg_gunlock;
1851
c752666c 1852 for (blk = leaf_no; blk; blk = nblk) {
b3b94faa
DT
1853 error = get_leaf(dip, blk, &bh);
1854 if (error)
1855 goto out_end_trans;
c752666c
SW
1856 tmp_leaf = (struct gfs2_leaf *)bh->b_data;
1857 nblk = be64_to_cpu(tmp_leaf->lf_next);
b3b94faa
DT
1858 brelse(bh);
1859
1860 gfs2_free_meta(dip, blk, 1);
1861
1862 if (!dip->i_di.di_blocks)
1863 gfs2_consist_inode(dip);
1864 dip->i_di.di_blocks--;
1865 }
1866
e13940ba 1867 error = gfs2_dir_write_data(dip, ht, index * sizeof(uint64_t), size);
b3b94faa
DT
1868 if (error != size) {
1869 if (error >= 0)
1870 error = -EIO;
1871 goto out_end_trans;
1872 }
1873
1874 error = gfs2_meta_inode_buffer(dip, &dibh);
1875 if (error)
1876 goto out_end_trans;
1877
d4e9c4c3 1878 gfs2_trans_add_bh(dip->i_gl, dibh, 1);
b3b94faa
DT
1879 gfs2_dinode_out(&dip->i_di, dibh->b_data);
1880 brelse(dibh);
1881
1882 out_end_trans:
1883 gfs2_trans_end(sdp);
1884
1885 out_rg_gunlock:
1886 gfs2_glock_dq_m(rlist.rl_rgrps, rlist.rl_ghs);
1887
1888 out_rlist:
1889 gfs2_rlist_free(&rlist);
1890 gfs2_glock_dq_uninit(&dip->i_alloc.al_ri_gh);
1891
1892 out_qs:
1893 gfs2_quota_unhold(dip);
1894
1895 out:
1896 gfs2_alloc_put(dip);
1897 kfree(ht);
1898
1899 return error;
1900}
1901
1902/**
1903 * gfs2_dir_exhash_dealloc - free all the leaf blocks in a directory
1904 * @dip: the directory
1905 *
1906 * Dealloc all on-disk directory leaves to FREEMETA state
1907 * Change on-disk inode type to "regular file"
1908 *
1909 * Returns: errno
1910 */
1911
1912int gfs2_dir_exhash_dealloc(struct gfs2_inode *dip)
1913{
1914 struct gfs2_sbd *sdp = dip->i_sbd;
1915 struct buffer_head *bh;
1916 int error;
1917
1918 /* Dealloc on-disk leaves to FREEMETA state */
1919 error = foreach_leaf(dip, leaf_dealloc, NULL);
1920 if (error)
1921 return error;
1922
1923 /* Make this a regular file in case we crash.
1924 (We don't want to free these blocks a second time.) */
1925
1926 error = gfs2_trans_begin(sdp, RES_DINODE, 0);
1927 if (error)
1928 return error;
1929
1930 error = gfs2_meta_inode_buffer(dip, &bh);
1931 if (!error) {
d4e9c4c3 1932 gfs2_trans_add_bh(dip->i_gl, bh, 1);
568f4c96
SW
1933 ((struct gfs2_dinode *)bh->b_data)->di_mode =
1934 cpu_to_be32(S_IFREG);
b3b94faa
DT
1935 brelse(bh);
1936 }
1937
1938 gfs2_trans_end(sdp);
1939
1940 return error;
1941}
1942
1943/**
1944 * gfs2_diradd_alloc_required - find if adding entry will require an allocation
1945 * @ip: the file being written to
1946 * @filname: the filename that's going to be added
b3b94faa 1947 *
c752666c 1948 * Returns: 1 if alloc required, 0 if not, -ve on error
b3b94faa
DT
1949 */
1950
c752666c
SW
1951int gfs2_diradd_alloc_required(struct inode *inode,
1952 const struct qstr *name)
b3b94faa 1953{
c752666c
SW
1954 struct gfs2_dirent *dent;
1955 struct buffer_head *bh;
b3b94faa 1956
c752666c
SW
1957 dent = gfs2_dirent_search(inode, name, gfs2_dirent_find_space, &bh);
1958 if (!dent)
1959 return 1;
1960 if (IS_ERR(dent))
1961 return PTR_ERR(dent);
1962 brelse(bh);
1963 return 0;
b3b94faa
DT
1964}
1965
This page took 0.110108 seconds and 5 git commands to generate.