blob: 2a6a895ca73e542c571cb47d3ac7b86ccfe7511d [file] [log] [blame]
Dave Chinner0b61f8a2018-06-05 19:42:14 -07001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
Nathan Scott7b718762005-11-02 14:58:39 +11003 * Copyright (c) 2000,2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 */
6#ifndef __XFS_EXTFREE_ITEM_H__
7#define __XFS_EXTFREE_ITEM_H__
8
Dave Chinner9fbe24d2013-08-12 20:49:25 +10009/* kernel only EFI/EFD definitions */
10
Linus Torvalds1da177e2005-04-16 15:20:36 -070011struct xfs_mount;
12struct kmem_zone;
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014/*
15 * Max number of extents in fast allocation path.
16 */
17#define XFS_EFI_MAX_FAST_EXTENTS 16
18
19/*
Dave Chinnerb199c8a2010-12-20 11:59:49 +110020 * Define EFI flag bits. Manipulated by set/clear/test_bit operators.
Linus Torvalds1da177e2005-04-16 15:20:36 -070021 */
Dave Chinnerb199c8a2010-12-20 11:59:49 +110022#define XFS_EFI_RECOVERED 1
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
24/*
Dave Chinner666d6442013-04-03 14:09:21 +110025 * This is the "extent free intention" log item. It is used to log the fact
26 * that some extents need to be free. It is used in conjunction with the
27 * "extent free done" log item described below.
28 *
29 * The EFI is reference counted so that it is not freed prior to both the EFI
Brian Foster8d99fe92015-08-19 09:51:16 +100030 * and EFD being committed and unpinned. This ensures the EFI is inserted into
31 * the AIL even in the event of out of order EFI/EFD processing. In other words,
32 * an EFI is born with two references:
33 *
34 * 1.) an EFI held reference to track EFI AIL insertion
35 * 2.) an EFD held reference to track EFD commit
36 *
37 * On allocation, both references are the responsibility of the caller. Once the
38 * EFI is added to and dirtied in a transaction, ownership of reference one
39 * transfers to the transaction. The reference is dropped once the EFI is
40 * inserted to the AIL or in the event of failure along the way (e.g., commit
41 * failure, log I/O error, etc.). Note that the caller remains responsible for
42 * the EFD reference under all circumstances to this point. The caller has no
43 * means to detect failure once the transaction is committed, however.
44 * Therefore, an EFD is required after this point, even in the event of
45 * unrelated failure.
46 *
47 * Once an EFD is allocated and dirtied in a transaction, reference two
48 * transfers to the transaction. The EFD reference is dropped once it reaches
49 * the unpin handler. Similar to the EFI, the reference also drops in the event
50 * of commit failure or log I/O errors. Note that the EFD is not inserted in the
51 * AIL, so at this point both the EFI and EFD are freed.
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 */
53typedef struct xfs_efi_log_item {
54 xfs_log_item_t efi_item;
Dave Chinner666d6442013-04-03 14:09:21 +110055 atomic_t efi_refcount;
Dave Chinnerb199c8a2010-12-20 11:59:49 +110056 atomic_t efi_next_extent;
57 unsigned long efi_flags; /* misc flags */
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 xfs_efi_log_format_t efi_format;
59} xfs_efi_log_item_t;
60
61/*
62 * This is the "extent free done" log item. It is used to log
63 * the fact that some extents earlier mentioned in an efi item
64 * have been freed.
65 */
66typedef struct xfs_efd_log_item {
67 xfs_log_item_t efd_item;
68 xfs_efi_log_item_t *efd_efip;
69 uint efd_next_extent;
70 xfs_efd_log_format_t efd_format;
71} xfs_efd_log_item_t;
72
73/*
74 * Max number of extents in fast allocation path.
75 */
76#define XFS_EFD_MAX_FAST_EXTENTS 16
77
78extern struct kmem_zone *xfs_efi_zone;
79extern struct kmem_zone *xfs_efd_zone;
80
81xfs_efi_log_item_t *xfs_efi_init(struct xfs_mount *, uint);
82xfs_efd_log_item_t *xfs_efd_init(struct xfs_mount *, xfs_efi_log_item_t *,
83 uint);
Tim Shimmin6d192a92006-06-09 14:55:38 +100084int xfs_efi_copy_format(xfs_log_iovec_t *buf,
85 xfs_efi_log_format_t *dst_efi_fmt);
Christoph Hellwig7d795ca2005-06-21 15:41:19 +100086void xfs_efi_item_free(xfs_efi_log_item_t *);
Brian Foster5e4b5382015-08-19 09:50:12 +100087void xfs_efi_release(struct xfs_efi_log_item *);
Christoph Hellwig7d795ca2005-06-21 15:41:19 +100088
Darrick J. Wongdc423752016-08-03 11:23:49 +100089int xfs_efi_recover(struct xfs_mount *mp,
90 struct xfs_efi_log_item *efip);
91
Linus Torvalds1da177e2005-04-16 15:20:36 -070092#endif /* __XFS_EXTFREE_ITEM_H__ */