Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[linux-2.6] / fs / xfs / quota / xfs_dquot_item.c
1 /*
2  * Copyright (c) 2000-2003 Silicon Graphics, Inc.
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_bit.h"
21 #include "xfs_log.h"
22 #include "xfs_inum.h"
23 #include "xfs_trans.h"
24 #include "xfs_sb.h"
25 #include "xfs_ag.h"
26 #include "xfs_dir2.h"
27 #include "xfs_alloc.h"
28 #include "xfs_dmapi.h"
29 #include "xfs_quota.h"
30 #include "xfs_mount.h"
31 #include "xfs_bmap_btree.h"
32 #include "xfs_alloc_btree.h"
33 #include "xfs_ialloc_btree.h"
34 #include "xfs_dir2_sf.h"
35 #include "xfs_attr_sf.h"
36 #include "xfs_dinode.h"
37 #include "xfs_inode.h"
38 #include "xfs_bmap.h"
39 #include "xfs_btree.h"
40 #include "xfs_ialloc.h"
41 #include "xfs_rtalloc.h"
42 #include "xfs_error.h"
43 #include "xfs_itable.h"
44 #include "xfs_rw.h"
45 #include "xfs_acl.h"
46 #include "xfs_cap.h"
47 #include "xfs_mac.h"
48 #include "xfs_attr.h"
49 #include "xfs_buf_item.h"
50 #include "xfs_trans_priv.h"
51 #include "xfs_qm.h"
52
53 /*
54  * returns the number of iovecs needed to log the given dquot item.
55  */
56 /* ARGSUSED */
57 STATIC uint
58 xfs_qm_dquot_logitem_size(
59         xfs_dq_logitem_t        *logitem)
60 {
61         /*
62          * we need only two iovecs, one for the format, one for the real thing
63          */
64         return (2);
65 }
66
67 /*
68  * fills in the vector of log iovecs for the given dquot log item.
69  */
70 STATIC void
71 xfs_qm_dquot_logitem_format(
72         xfs_dq_logitem_t        *logitem,
73         xfs_log_iovec_t         *logvec)
74 {
75         ASSERT(logitem);
76         ASSERT(logitem->qli_dquot);
77
78         logvec->i_addr = (xfs_caddr_t)&logitem->qli_format;
79         logvec->i_len  = sizeof(xfs_dq_logformat_t);
80         XLOG_VEC_SET_TYPE(logvec, XLOG_REG_TYPE_QFORMAT);
81         logvec++;
82         logvec->i_addr = (xfs_caddr_t)&logitem->qli_dquot->q_core;
83         logvec->i_len  = sizeof(xfs_disk_dquot_t);
84         XLOG_VEC_SET_TYPE(logvec, XLOG_REG_TYPE_DQUOT);
85
86         ASSERT(2 == logitem->qli_item.li_desc->lid_size);
87         logitem->qli_format.qlf_size = 2;
88
89 }
90
91 /*
92  * Increment the pin count of the given dquot.
93  * This value is protected by pinlock spinlock in the xQM structure.
94  */
95 STATIC void
96 xfs_qm_dquot_logitem_pin(
97         xfs_dq_logitem_t *logitem)
98 {
99         unsigned long   s;
100         xfs_dquot_t *dqp;
101
102         dqp = logitem->qli_dquot;
103         ASSERT(XFS_DQ_IS_LOCKED(dqp));
104         s = XFS_DQ_PINLOCK(dqp);
105         dqp->q_pincount++;
106         XFS_DQ_PINUNLOCK(dqp, s);
107 }
108
109 /*
110  * Decrement the pin count of the given dquot, and wake up
111  * anyone in xfs_dqwait_unpin() if the count goes to 0.  The
112  * dquot must have been previously pinned with a call to xfs_dqpin().
113  */
114 /* ARGSUSED */
115 STATIC void
116 xfs_qm_dquot_logitem_unpin(
117         xfs_dq_logitem_t *logitem,
118         int               stale)
119 {
120         unsigned long   s;
121         xfs_dquot_t *dqp;
122
123         dqp = logitem->qli_dquot;
124         ASSERT(dqp->q_pincount > 0);
125         s = XFS_DQ_PINLOCK(dqp);
126         dqp->q_pincount--;
127         if (dqp->q_pincount == 0) {
128                 sv_broadcast(&dqp->q_pinwait);
129         }
130         XFS_DQ_PINUNLOCK(dqp, s);
131 }
132
133 /* ARGSUSED */
134 STATIC void
135 xfs_qm_dquot_logitem_unpin_remove(
136         xfs_dq_logitem_t *logitem,
137         xfs_trans_t      *tp)
138 {
139         xfs_qm_dquot_logitem_unpin(logitem, 0);
140 }
141
142 /*
143  * Given the logitem, this writes the corresponding dquot entry to disk
144  * asynchronously. This is called with the dquot entry securely locked;
145  * we simply get xfs_qm_dqflush() to do the work, and unlock the dquot
146  * at the end.
147  */
148 STATIC void
149 xfs_qm_dquot_logitem_push(
150         xfs_dq_logitem_t        *logitem)
151 {
152         xfs_dquot_t     *dqp;
153
154         dqp = logitem->qli_dquot;
155
156         ASSERT(XFS_DQ_IS_LOCKED(dqp));
157         ASSERT(XFS_DQ_IS_FLUSH_LOCKED(dqp));
158
159         /*
160          * Since we were able to lock the dquot's flush lock and
161          * we found it on the AIL, the dquot must be dirty.  This
162          * is because the dquot is removed from the AIL while still
163          * holding the flush lock in xfs_dqflush_done().  Thus, if
164          * we found it in the AIL and were able to obtain the flush
165          * lock without sleeping, then there must not have been
166          * anyone in the process of flushing the dquot.
167          */
168         xfs_qm_dqflush(dqp, XFS_B_DELWRI);
169         xfs_dqunlock(dqp);
170 }
171
172 /*ARGSUSED*/
173 STATIC xfs_lsn_t
174 xfs_qm_dquot_logitem_committed(
175         xfs_dq_logitem_t        *l,
176         xfs_lsn_t               lsn)
177 {
178         /*
179          * We always re-log the entire dquot when it becomes dirty,
180          * so, the latest copy _is_ the only one that matters.
181          */
182         return (lsn);
183 }
184
185
186 /*
187  * This is called to wait for the given dquot to be unpinned.
188  * Most of these pin/unpin routines are plagiarized from inode code.
189  */
190 void
191 xfs_qm_dqunpin_wait(
192         xfs_dquot_t     *dqp)
193 {
194         SPLDECL(s);
195
196         ASSERT(XFS_DQ_IS_LOCKED(dqp));
197         if (dqp->q_pincount == 0) {
198                 return;
199         }
200
201         /*
202          * Give the log a push so we don't wait here too long.
203          */
204         xfs_log_force(dqp->q_mount, (xfs_lsn_t)0, XFS_LOG_FORCE);
205         s = XFS_DQ_PINLOCK(dqp);
206         if (dqp->q_pincount == 0) {
207                 XFS_DQ_PINUNLOCK(dqp, s);
208                 return;
209         }
210         sv_wait(&(dqp->q_pinwait), PINOD,
211                 &(XFS_DQ_TO_QINF(dqp)->qi_pinlock), s);
212 }
213
214 /*
215  * This is called when IOP_TRYLOCK returns XFS_ITEM_PUSHBUF to indicate that
216  * the dquot is locked by us, but the flush lock isn't. So, here we are
217  * going to see if the relevant dquot buffer is incore, waiting on DELWRI.
218  * If so, we want to push it out to help us take this item off the AIL as soon
219  * as possible.
220  *
221  * We must not be holding the AIL_LOCK at this point. Calling incore() to
222  * search the buffer cache can be a time consuming thing, and AIL_LOCK is a
223  * spinlock.
224  */
225 STATIC void
226 xfs_qm_dquot_logitem_pushbuf(
227         xfs_dq_logitem_t    *qip)
228 {
229         xfs_dquot_t     *dqp;
230         xfs_mount_t     *mp;
231         xfs_buf_t       *bp;
232         uint            dopush;
233
234         dqp = qip->qli_dquot;
235         ASSERT(XFS_DQ_IS_LOCKED(dqp));
236
237         /*
238          * The qli_pushbuf_flag keeps others from
239          * trying to duplicate our effort.
240          */
241         ASSERT(qip->qli_pushbuf_flag != 0);
242         ASSERT(qip->qli_push_owner == current_pid());
243
244         /*
245          * If flushlock isn't locked anymore, chances are that the
246          * inode flush completed and the inode was taken off the AIL.
247          * So, just get out.
248          */
249         if (!issemalocked(&(dqp->q_flock))  ||
250             ((qip->qli_item.li_flags & XFS_LI_IN_AIL) == 0)) {
251                 qip->qli_pushbuf_flag = 0;
252                 xfs_dqunlock(dqp);
253                 return;
254         }
255         mp = dqp->q_mount;
256         bp = xfs_incore(mp->m_ddev_targp, qip->qli_format.qlf_blkno,
257                     XFS_QI_DQCHUNKLEN(mp),
258                     XFS_INCORE_TRYLOCK);
259         if (bp != NULL) {
260                 if (XFS_BUF_ISDELAYWRITE(bp)) {
261                         dopush = ((qip->qli_item.li_flags & XFS_LI_IN_AIL) &&
262                                   issemalocked(&(dqp->q_flock)));
263                         qip->qli_pushbuf_flag = 0;
264                         xfs_dqunlock(dqp);
265
266                         if (XFS_BUF_ISPINNED(bp)) {
267                                 xfs_log_force(mp, (xfs_lsn_t)0,
268                                               XFS_LOG_FORCE);
269                         }
270                         if (dopush) {
271 #ifdef XFSRACEDEBUG
272                                 delay_for_intr();
273                                 delay(300);
274 #endif
275                                 xfs_bawrite(mp, bp);
276                         } else {
277                                 xfs_buf_relse(bp);
278                         }
279                 } else {
280                         qip->qli_pushbuf_flag = 0;
281                         xfs_dqunlock(dqp);
282                         xfs_buf_relse(bp);
283                 }
284                 return;
285         }
286
287         qip->qli_pushbuf_flag = 0;
288         xfs_dqunlock(dqp);
289 }
290
291 /*
292  * This is called to attempt to lock the dquot associated with this
293  * dquot log item.  Don't sleep on the dquot lock or the flush lock.
294  * If the flush lock is already held, indicating that the dquot has
295  * been or is in the process of being flushed, then see if we can
296  * find the dquot's buffer in the buffer cache without sleeping.  If
297  * we can and it is marked delayed write, then we want to send it out.
298  * We delay doing so until the push routine, though, to avoid sleeping
299  * in any device strategy routines.
300  */
301 STATIC uint
302 xfs_qm_dquot_logitem_trylock(
303         xfs_dq_logitem_t        *qip)
304 {
305         xfs_dquot_t             *dqp;
306         uint                    retval;
307
308         dqp = qip->qli_dquot;
309         if (dqp->q_pincount > 0)
310                 return (XFS_ITEM_PINNED);
311
312         if (! xfs_qm_dqlock_nowait(dqp))
313                 return (XFS_ITEM_LOCKED);
314
315         retval = XFS_ITEM_SUCCESS;
316         if (! xfs_qm_dqflock_nowait(dqp)) {
317                 /*
318                  * The dquot is already being flushed.  It may have been
319                  * flushed delayed write, however, and we don't want to
320                  * get stuck waiting for that to complete.  So, we want to check
321                  * to see if we can lock the dquot's buffer without sleeping.
322                  * If we can and it is marked for delayed write, then we
323                  * hold it and send it out from the push routine.  We don't
324                  * want to do that now since we might sleep in the device
325                  * strategy routine.  We also don't want to grab the buffer lock
326                  * here because we'd like not to call into the buffer cache
327                  * while holding the AIL_LOCK.
328                  * Make sure to only return PUSHBUF if we set pushbuf_flag
329                  * ourselves.  If someone else is doing it then we don't
330                  * want to go to the push routine and duplicate their efforts.
331                  */
332                 if (qip->qli_pushbuf_flag == 0) {
333                         qip->qli_pushbuf_flag = 1;
334                         ASSERT(qip->qli_format.qlf_blkno == dqp->q_blkno);
335 #ifdef DEBUG
336                         qip->qli_push_owner = current_pid();
337 #endif
338                         /*
339                          * The dquot is left locked.
340                          */
341                         retval = XFS_ITEM_PUSHBUF;
342                 } else {
343                         retval = XFS_ITEM_FLUSHING;
344                         xfs_dqunlock_nonotify(dqp);
345                 }
346         }
347
348         ASSERT(qip->qli_item.li_flags & XFS_LI_IN_AIL);
349         return (retval);
350 }
351
352
353 /*
354  * Unlock the dquot associated with the log item.
355  * Clear the fields of the dquot and dquot log item that
356  * are specific to the current transaction.  If the
357  * hold flags is set, do not unlock the dquot.
358  */
359 STATIC void
360 xfs_qm_dquot_logitem_unlock(
361         xfs_dq_logitem_t    *ql)
362 {
363         xfs_dquot_t     *dqp;
364
365         ASSERT(ql != NULL);
366         dqp = ql->qli_dquot;
367         ASSERT(XFS_DQ_IS_LOCKED(dqp));
368
369         /*
370          * Clear the transaction pointer in the dquot
371          */
372         dqp->q_transp = NULL;
373
374         /*
375          * dquots are never 'held' from getting unlocked at the end of
376          * a transaction.  Their locking and unlocking is hidden inside the
377          * transaction layer, within trans_commit. Hence, no LI_HOLD flag
378          * for the logitem.
379          */
380         xfs_dqunlock(dqp);
381 }
382
383
384 /*
385  * The transaction with the dquot locked has aborted.  The dquot
386  * must not be dirty within the transaction.  We simply unlock just
387  * as if the transaction had been cancelled.
388  */
389 STATIC void
390 xfs_qm_dquot_logitem_abort(
391         xfs_dq_logitem_t    *ql)
392 {
393         xfs_qm_dquot_logitem_unlock(ql);
394 }
395
396 /*
397  * this needs to stamp an lsn into the dquot, I think.
398  * rpc's that look at user dquot's would then have to
399  * push on the dependency recorded in the dquot
400  */
401 /* ARGSUSED */
402 STATIC void
403 xfs_qm_dquot_logitem_committing(
404         xfs_dq_logitem_t        *l,
405         xfs_lsn_t               lsn)
406 {
407         return;
408 }
409
410
411 /*
412  * This is the ops vector for dquots
413  */
414 STATIC struct xfs_item_ops xfs_dquot_item_ops = {
415         .iop_size       = (uint(*)(xfs_log_item_t*))xfs_qm_dquot_logitem_size,
416         .iop_format     = (void(*)(xfs_log_item_t*, xfs_log_iovec_t*))
417                                         xfs_qm_dquot_logitem_format,
418         .iop_pin        = (void(*)(xfs_log_item_t*))xfs_qm_dquot_logitem_pin,
419         .iop_unpin      = (void(*)(xfs_log_item_t*, int))
420                                         xfs_qm_dquot_logitem_unpin,
421         .iop_unpin_remove = (void(*)(xfs_log_item_t*, xfs_trans_t*))
422                                         xfs_qm_dquot_logitem_unpin_remove,
423         .iop_trylock    = (uint(*)(xfs_log_item_t*))
424                                         xfs_qm_dquot_logitem_trylock,
425         .iop_unlock     = (void(*)(xfs_log_item_t*))xfs_qm_dquot_logitem_unlock,
426         .iop_committed  = (xfs_lsn_t(*)(xfs_log_item_t*, xfs_lsn_t))
427                                         xfs_qm_dquot_logitem_committed,
428         .iop_push       = (void(*)(xfs_log_item_t*))xfs_qm_dquot_logitem_push,
429         .iop_abort      = (void(*)(xfs_log_item_t*))xfs_qm_dquot_logitem_abort,
430         .iop_pushbuf    = (void(*)(xfs_log_item_t*))
431                                         xfs_qm_dquot_logitem_pushbuf,
432         .iop_committing = (void(*)(xfs_log_item_t*, xfs_lsn_t))
433                                         xfs_qm_dquot_logitem_committing
434 };
435
436 /*
437  * Initialize the dquot log item for a newly allocated dquot.
438  * The dquot isn't locked at this point, but it isn't on any of the lists
439  * either, so we don't care.
440  */
441 void
442 xfs_qm_dquot_logitem_init(
443         struct xfs_dquot *dqp)
444 {
445         xfs_dq_logitem_t  *lp;
446         lp = &dqp->q_logitem;
447
448         lp->qli_item.li_type = XFS_LI_DQUOT;
449         lp->qli_item.li_ops = &xfs_dquot_item_ops;
450         lp->qli_item.li_mountp = dqp->q_mount;
451         lp->qli_dquot = dqp;
452         lp->qli_format.qlf_type = XFS_LI_DQUOT;
453         lp->qli_format.qlf_id = be32_to_cpu(dqp->q_core.d_id);
454         lp->qli_format.qlf_blkno = dqp->q_blkno;
455         lp->qli_format.qlf_len = 1;
456         /*
457          * This is just the offset of this dquot within its buffer
458          * (which is currently 1 FSB and probably won't change).
459          * Hence 32 bits for this offset should be just fine.
460          * Alternatively, we can store (bufoffset / sizeof(xfs_dqblk_t))
461          * here, and recompute it at recovery time.
462          */
463         lp->qli_format.qlf_boffset = (__uint32_t)dqp->q_bufoffset;
464 }
465
466 /*------------------  QUOTAOFF LOG ITEMS  -------------------*/
467
468 /*
469  * This returns the number of iovecs needed to log the given quotaoff item.
470  * We only need 1 iovec for an quotaoff item.  It just logs the
471  * quotaoff_log_format structure.
472  */
473 /*ARGSUSED*/
474 STATIC uint
475 xfs_qm_qoff_logitem_size(xfs_qoff_logitem_t *qf)
476 {
477         return (1);
478 }
479
480 /*
481  * This is called to fill in the vector of log iovecs for the
482  * given quotaoff log item. We use only 1 iovec, and we point that
483  * at the quotaoff_log_format structure embedded in the quotaoff item.
484  * It is at this point that we assert that all of the extent
485  * slots in the quotaoff item have been filled.
486  */
487 STATIC void
488 xfs_qm_qoff_logitem_format(xfs_qoff_logitem_t   *qf,
489                            xfs_log_iovec_t      *log_vector)
490 {
491         ASSERT(qf->qql_format.qf_type == XFS_LI_QUOTAOFF);
492
493         log_vector->i_addr = (xfs_caddr_t)&(qf->qql_format);
494         log_vector->i_len = sizeof(xfs_qoff_logitem_t);
495         XLOG_VEC_SET_TYPE(log_vector, XLOG_REG_TYPE_QUOTAOFF);
496         qf->qql_format.qf_size = 1;
497 }
498
499
500 /*
501  * Pinning has no meaning for an quotaoff item, so just return.
502  */
503 /*ARGSUSED*/
504 STATIC void
505 xfs_qm_qoff_logitem_pin(xfs_qoff_logitem_t *qf)
506 {
507         return;
508 }
509
510
511 /*
512  * Since pinning has no meaning for an quotaoff item, unpinning does
513  * not either.
514  */
515 /*ARGSUSED*/
516 STATIC void
517 xfs_qm_qoff_logitem_unpin(xfs_qoff_logitem_t *qf, int stale)
518 {
519         return;
520 }
521
522 /*ARGSUSED*/
523 STATIC void
524 xfs_qm_qoff_logitem_unpin_remove(xfs_qoff_logitem_t *qf, xfs_trans_t *tp)
525 {
526         return;
527 }
528
529 /*
530  * Quotaoff items have no locking, so just return success.
531  */
532 /*ARGSUSED*/
533 STATIC uint
534 xfs_qm_qoff_logitem_trylock(xfs_qoff_logitem_t *qf)
535 {
536         return XFS_ITEM_LOCKED;
537 }
538
539 /*
540  * Quotaoff items have no locking or pushing, so return failure
541  * so that the caller doesn't bother with us.
542  */
543 /*ARGSUSED*/
544 STATIC void
545 xfs_qm_qoff_logitem_unlock(xfs_qoff_logitem_t *qf)
546 {
547         return;
548 }
549
550 /*
551  * The quotaoff-start-item is logged only once and cannot be moved in the log,
552  * so simply return the lsn at which it's been logged.
553  */
554 /*ARGSUSED*/
555 STATIC xfs_lsn_t
556 xfs_qm_qoff_logitem_committed(xfs_qoff_logitem_t *qf, xfs_lsn_t lsn)
557 {
558         return (lsn);
559 }
560
561 /*
562  * The transaction of which this QUOTAOFF is a part has been aborted.
563  * Just clean up after ourselves.
564  * Shouldn't this never happen in the case of qoffend logitems? XXX
565  */
566 STATIC void
567 xfs_qm_qoff_logitem_abort(xfs_qoff_logitem_t *qf)
568 {
569         kmem_free(qf, sizeof(xfs_qoff_logitem_t));
570 }
571
572 /*
573  * There isn't much you can do to push on an quotaoff item.  It is simply
574  * stuck waiting for the log to be flushed to disk.
575  */
576 /*ARGSUSED*/
577 STATIC void
578 xfs_qm_qoff_logitem_push(xfs_qoff_logitem_t *qf)
579 {
580         return;
581 }
582
583
584 /*ARGSUSED*/
585 STATIC xfs_lsn_t
586 xfs_qm_qoffend_logitem_committed(
587         xfs_qoff_logitem_t *qfe,
588         xfs_lsn_t lsn)
589 {
590         xfs_qoff_logitem_t      *qfs;
591         SPLDECL(s);
592
593         qfs = qfe->qql_start_lip;
594         AIL_LOCK(qfs->qql_item.li_mountp,s);
595         /*
596          * Delete the qoff-start logitem from the AIL.
597          * xfs_trans_delete_ail() drops the AIL lock.
598          */
599         xfs_trans_delete_ail(qfs->qql_item.li_mountp, (xfs_log_item_t *)qfs, s);
600         kmem_free(qfs, sizeof(xfs_qoff_logitem_t));
601         kmem_free(qfe, sizeof(xfs_qoff_logitem_t));
602         return (xfs_lsn_t)-1;
603 }
604
605 /*
606  * XXX rcc - don't know quite what to do with this.  I think we can
607  * just ignore it.  The only time that isn't the case is if we allow
608  * the client to somehow see that quotas have been turned off in which
609  * we can't allow that to get back until the quotaoff hits the disk.
610  * So how would that happen?  Also, do we need different routines for
611  * quotaoff start and quotaoff end?  I suspect the answer is yes but
612  * to be sure, I need to look at the recovery code and see how quota off
613  * recovery is handled (do we roll forward or back or do something else).
614  * If we roll forwards or backwards, then we need two separate routines,
615  * one that does nothing and one that stamps in the lsn that matters
616  * (truly makes the quotaoff irrevocable).  If we do something else,
617  * then maybe we don't need two.
618  */
619 /* ARGSUSED */
620 STATIC void
621 xfs_qm_qoff_logitem_committing(xfs_qoff_logitem_t *qip, xfs_lsn_t commit_lsn)
622 {
623         return;
624 }
625
626 /* ARGSUSED */
627 STATIC void
628 xfs_qm_qoffend_logitem_committing(xfs_qoff_logitem_t *qip, xfs_lsn_t commit_lsn)
629 {
630         return;
631 }
632
633 STATIC struct xfs_item_ops xfs_qm_qoffend_logitem_ops = {
634         .iop_size       = (uint(*)(xfs_log_item_t*))xfs_qm_qoff_logitem_size,
635         .iop_format     = (void(*)(xfs_log_item_t*, xfs_log_iovec_t*))
636                                         xfs_qm_qoff_logitem_format,
637         .iop_pin        = (void(*)(xfs_log_item_t*))xfs_qm_qoff_logitem_pin,
638         .iop_unpin      = (void(*)(xfs_log_item_t* ,int))
639                                         xfs_qm_qoff_logitem_unpin,
640         .iop_unpin_remove = (void(*)(xfs_log_item_t*,xfs_trans_t*))
641                                         xfs_qm_qoff_logitem_unpin_remove,
642         .iop_trylock    = (uint(*)(xfs_log_item_t*))xfs_qm_qoff_logitem_trylock,
643         .iop_unlock     = (void(*)(xfs_log_item_t*))xfs_qm_qoff_logitem_unlock,
644         .iop_committed  = (xfs_lsn_t(*)(xfs_log_item_t*, xfs_lsn_t))
645                                         xfs_qm_qoffend_logitem_committed,
646         .iop_push       = (void(*)(xfs_log_item_t*))xfs_qm_qoff_logitem_push,
647         .iop_abort      = (void(*)(xfs_log_item_t*))xfs_qm_qoff_logitem_abort,
648         .iop_pushbuf    = NULL,
649         .iop_committing = (void(*)(xfs_log_item_t*, xfs_lsn_t))
650                                         xfs_qm_qoffend_logitem_committing
651 };
652
653 /*
654  * This is the ops vector shared by all quotaoff-start log items.
655  */
656 STATIC struct xfs_item_ops xfs_qm_qoff_logitem_ops = {
657         .iop_size       = (uint(*)(xfs_log_item_t*))xfs_qm_qoff_logitem_size,
658         .iop_format     = (void(*)(xfs_log_item_t*, xfs_log_iovec_t*))
659                                         xfs_qm_qoff_logitem_format,
660         .iop_pin        = (void(*)(xfs_log_item_t*))xfs_qm_qoff_logitem_pin,
661         .iop_unpin      = (void(*)(xfs_log_item_t*, int))
662                                         xfs_qm_qoff_logitem_unpin,
663         .iop_unpin_remove = (void(*)(xfs_log_item_t*,xfs_trans_t*))
664                                         xfs_qm_qoff_logitem_unpin_remove,
665         .iop_trylock    = (uint(*)(xfs_log_item_t*))xfs_qm_qoff_logitem_trylock,
666         .iop_unlock     = (void(*)(xfs_log_item_t*))xfs_qm_qoff_logitem_unlock,
667         .iop_committed  = (xfs_lsn_t(*)(xfs_log_item_t*, xfs_lsn_t))
668                                         xfs_qm_qoff_logitem_committed,
669         .iop_push       = (void(*)(xfs_log_item_t*))xfs_qm_qoff_logitem_push,
670         .iop_abort      = (void(*)(xfs_log_item_t*))xfs_qm_qoff_logitem_abort,
671         .iop_pushbuf    = NULL,
672         .iop_committing = (void(*)(xfs_log_item_t*, xfs_lsn_t))
673                                         xfs_qm_qoff_logitem_committing
674 };
675
676 /*
677  * Allocate and initialize an quotaoff item of the correct quota type(s).
678  */
679 xfs_qoff_logitem_t *
680 xfs_qm_qoff_logitem_init(
681         struct xfs_mount *mp,
682         xfs_qoff_logitem_t *start,
683         uint flags)
684 {
685         xfs_qoff_logitem_t      *qf;
686
687         qf = (xfs_qoff_logitem_t*) kmem_zalloc(sizeof(xfs_qoff_logitem_t), KM_SLEEP);
688
689         qf->qql_item.li_type = XFS_LI_QUOTAOFF;
690         if (start)
691                 qf->qql_item.li_ops = &xfs_qm_qoffend_logitem_ops;
692         else
693                 qf->qql_item.li_ops = &xfs_qm_qoff_logitem_ops;
694         qf->qql_item.li_mountp = mp;
695         qf->qql_format.qf_type = XFS_LI_QUOTAOFF;
696         qf->qql_format.qf_flags = flags;
697         qf->qql_start_lip = start;
698         return (qf);
699 }