]> git.karo-electronics.de Git - karo-tx-linux.git/blob - fs/xfs/xfs_icreate_item.c
Merge branch 'for-3.13/logitech' into for-next
[karo-tx-linux.git] / fs / xfs / xfs_icreate_item.c
1 /*
2  * Copyright (c) 2008-2010, 2013 Dave Chinner
3  * All Rights Reserved.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it would be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write the Free Software Foundation,
16  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17  */
18 #include "xfs.h"
19 #include "xfs_fs.h"
20 #include "xfs_types.h"
21 #include "xfs_bit.h"
22 #include "xfs_log.h"
23 #include "xfs_trans.h"
24 #include "xfs_sb.h"
25 #include "xfs_ag.h"
26 #include "xfs_mount.h"
27 #include "xfs_trans_priv.h"
28 #include "xfs_error.h"
29 #include "xfs_icreate_item.h"
30
31 kmem_zone_t     *xfs_icreate_zone;              /* inode create item zone */
32
33 static inline struct xfs_icreate_item *ICR_ITEM(struct xfs_log_item *lip)
34 {
35         return container_of(lip, struct xfs_icreate_item, ic_item);
36 }
37
38 /*
39  * This returns the number of iovecs needed to log the given inode item.
40  *
41  * We only need one iovec for the icreate log structure.
42  */
43 STATIC void
44 xfs_icreate_item_size(
45         struct xfs_log_item     *lip,
46         int                     *nvecs,
47         int                     *nbytes)
48 {
49         *nvecs += 1;
50         *nbytes += sizeof(struct xfs_icreate_log);
51 }
52
53 /*
54  * This is called to fill in the vector of log iovecs for the
55  * given inode create log item.
56  */
57 STATIC void
58 xfs_icreate_item_format(
59         struct xfs_log_item     *lip,
60         struct xfs_log_iovec    *log_vector)
61 {
62         struct xfs_icreate_item *icp = ICR_ITEM(lip);
63
64         log_vector->i_addr = (xfs_caddr_t)&icp->ic_format;
65         log_vector->i_len  = sizeof(struct xfs_icreate_log);
66         log_vector->i_type = XLOG_REG_TYPE_ICREATE;
67 }
68
69
70 /* Pinning has no meaning for the create item, so just return. */
71 STATIC void
72 xfs_icreate_item_pin(
73         struct xfs_log_item     *lip)
74 {
75 }
76
77
78 /* pinning has no meaning for the create item, so just return. */
79 STATIC void
80 xfs_icreate_item_unpin(
81         struct xfs_log_item     *lip,
82         int                     remove)
83 {
84 }
85
86 STATIC void
87 xfs_icreate_item_unlock(
88         struct xfs_log_item     *lip)
89 {
90         struct xfs_icreate_item *icp = ICR_ITEM(lip);
91
92         if (icp->ic_item.li_flags & XFS_LI_ABORTED)
93                 kmem_zone_free(xfs_icreate_zone, icp);
94         return;
95 }
96
97 /*
98  * Because we have ordered buffers being tracked in the AIL for the inode
99  * creation, we don't need the create item after this. Hence we can free
100  * the log item and return -1 to tell the caller we're done with the item.
101  */
102 STATIC xfs_lsn_t
103 xfs_icreate_item_committed(
104         struct xfs_log_item     *lip,
105         xfs_lsn_t               lsn)
106 {
107         struct xfs_icreate_item *icp = ICR_ITEM(lip);
108
109         kmem_zone_free(xfs_icreate_zone, icp);
110         return (xfs_lsn_t)-1;
111 }
112
113 /* item can never get into the AIL */
114 STATIC uint
115 xfs_icreate_item_push(
116         struct xfs_log_item     *lip,
117         struct list_head        *buffer_list)
118 {
119         ASSERT(0);
120         return XFS_ITEM_SUCCESS;
121 }
122
123 /* Ordered buffers do the dependency tracking here, so this does nothing. */
124 STATIC void
125 xfs_icreate_item_committing(
126         struct xfs_log_item     *lip,
127         xfs_lsn_t               lsn)
128 {
129 }
130
131 /*
132  * This is the ops vector shared by all buf log items.
133  */
134 static struct xfs_item_ops xfs_icreate_item_ops = {
135         .iop_size       = xfs_icreate_item_size,
136         .iop_format     = xfs_icreate_item_format,
137         .iop_pin        = xfs_icreate_item_pin,
138         .iop_unpin      = xfs_icreate_item_unpin,
139         .iop_push       = xfs_icreate_item_push,
140         .iop_unlock     = xfs_icreate_item_unlock,
141         .iop_committed  = xfs_icreate_item_committed,
142         .iop_committing = xfs_icreate_item_committing,
143 };
144
145
146 /*
147  * Initialize the inode log item for a newly allocated (in-core) inode.
148  *
149  * Inode extents can only reside within an AG. Hence specify the starting
150  * block for the inode chunk by offset within an AG as well as the
151  * length of the allocated extent.
152  *
153  * This joins the item to the transaction and marks it dirty so
154  * that we don't need a separate call to do this, nor does the
155  * caller need to know anything about the icreate item.
156  */
157 void
158 xfs_icreate_log(
159         struct xfs_trans        *tp,
160         xfs_agnumber_t          agno,
161         xfs_agblock_t           agbno,
162         unsigned int            count,
163         unsigned int            inode_size,
164         xfs_agblock_t           length,
165         unsigned int            generation)
166 {
167         struct xfs_icreate_item *icp;
168
169         icp = kmem_zone_zalloc(xfs_icreate_zone, KM_SLEEP);
170
171         xfs_log_item_init(tp->t_mountp, &icp->ic_item, XFS_LI_ICREATE,
172                           &xfs_icreate_item_ops);
173
174         icp->ic_format.icl_type = XFS_LI_ICREATE;
175         icp->ic_format.icl_size = 1;    /* single vector */
176         icp->ic_format.icl_ag = cpu_to_be32(agno);
177         icp->ic_format.icl_agbno = cpu_to_be32(agbno);
178         icp->ic_format.icl_count = cpu_to_be32(count);
179         icp->ic_format.icl_isize = cpu_to_be32(inode_size);
180         icp->ic_format.icl_length = cpu_to_be32(length);
181         icp->ic_format.icl_gen = cpu_to_be32(generation);
182
183         xfs_trans_add_item(tp, &icp->ic_item);
184         tp->t_flags |= XFS_TRANS_DIRTY;
185         icp->ic_item.li_desc->lid_flags |= XFS_LID_DIRTY;
186 }