~ubuntu-branches/ubuntu/edgy/xfsprogs/edgy

« back to all changes in this revision

Viewing changes to libxfs/trans.c

  • Committer: Bazaar Package Importer
  • Author(s): Nathan Scott
  • Date: 2004-07-28 21:11:38 UTC
  • Revision ID: james.westby@ubuntu.com-20040728211138-0v4pdnunnp7na5lm
Tags: 2.6.20-1
* New upstream release.
* Fix xfs_io segfault on non-XFS files.  (closes: #260470)
* Fix packaging botch, deleted files included.  (closes: #260491)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
 
2
 * Copyright (c) 2000-2001 Silicon Graphics, Inc.  All Rights Reserved.
3
3
 *
4
4
 * This program is free software; you can redistribute it and/or modify it
5
5
 * under the terms of version 2 of the GNU General Public License as
11
11
 *
12
12
 * Further, this software is distributed without any warranty that it is
13
13
 * free of the rightful claim of any third person regarding infringement
14
 
 * or the like.  Any license provided herein, whether implied or
 
14
 * or the like.  Any license provided herein, whether implied or
15
15
 * otherwise, applies only to this software file.  Patent licenses, if
16
16
 * any, provided herein do not apply to combinations of this program with
17
17
 * other software, or any other product whatsoever.
37
37
 */
38
38
 
39
39
xfs_trans_t *
40
 
libxfs_trans_alloc(xfs_mount_t *mp, int type)
 
40
libxfs_trans_alloc(
 
41
        xfs_mount_t     *mp,
 
42
        int             type)
41
43
{
42
44
        xfs_trans_t     *ptr;
43
45
 
44
46
        if ((ptr = calloc(sizeof(xfs_trans_t), 1)) == NULL) {
45
 
                fprintf(stderr, "%s: xact calloc failed (%d bytes): %s\n",
 
47
                fprintf(stderr, _("%s: xact calloc failed (%d bytes): %s\n"),
46
48
                        progname, (int)sizeof(xfs_trans_t), strerror(errno));
47
49
                exit(1);
48
50
        }
57
59
}
58
60
 
59
61
xfs_trans_t *
60
 
libxfs_trans_dup(xfs_trans_t *tp)
 
62
libxfs_trans_dup(
 
63
        xfs_trans_t     *tp)
61
64
{
62
 
        xfs_trans_t *ptr;
 
65
        xfs_trans_t     *ptr;
63
66
 
64
67
        ptr = libxfs_trans_alloc(tp->t_mountp, tp->t_type);
65
68
#ifdef XACT_DEBUG
69
72
}
70
73
 
71
74
int
72
 
libxfs_trans_reserve(xfs_trans_t *tp,
73
 
        uint blocks, uint logspace, uint rtextents, uint flags, uint logcount)
 
75
libxfs_trans_reserve(
 
76
        xfs_trans_t     *tp,
 
77
        uint            blocks,
 
78
        uint            logspace,
 
79
        uint            rtextents,
 
80
        uint            flags,
 
81
        uint            logcount)
74
82
{
75
83
        xfs_sb_t        *mpsb = &tp->t_mountp->m_sb;
76
84
 
77
85
        /*
78
86
         * Attempt to reserve the needed disk blocks by decrementing
79
 
         * the number needed from the number available.  This will
 
87
         * the number needed from the number available.  This will
80
88
         * fail if the count would go below zero.
81
89
         */
82
90
        if (blocks > 0) {
88
96
}
89
97
 
90
98
void
91
 
libxfs_trans_cancel(xfs_trans_t *tp, int flags)
 
99
libxfs_trans_cancel(
 
100
        xfs_trans_t     *tp,
 
101
        int             flags)
92
102
{
93
103
#ifdef XACT_DEBUG
94
 
        xfs_trans_t *otp = tp;
 
104
        xfs_trans_t     *otp = tp;
95
105
#endif
96
106
        if (tp != NULL) {
97
107
                xfs_trans_free_items(tp, flags);
104
114
}
105
115
 
106
116
int
107
 
libxfs_trans_iget(xfs_mount_t *mp, xfs_trans_t *tp, xfs_ino_t ino,
108
 
                uint lock_flags, xfs_inode_t **ipp)
 
117
libxfs_trans_iget(
 
118
        xfs_mount_t             *mp,
 
119
        xfs_trans_t             *tp,
 
120
        xfs_ino_t               ino,
 
121
        uint                    lock_flags,
 
122
        xfs_inode_t             **ipp)
109
123
{
110
124
        int                     error;
111
125
        xfs_inode_t             *ip;
132
146
}
133
147
 
134
148
void
135
 
libxfs_trans_iput(xfs_trans_t *tp, xfs_inode_t *ip, uint lock_flags)
 
149
libxfs_trans_iput(
 
150
        xfs_trans_t             *tp,
 
151
        xfs_inode_t             *ip,
 
152
        uint                    lock_flags)
136
153
{
137
154
        xfs_inode_log_item_t    *iip;
138
155
        xfs_log_item_desc_t     *lidp;
156
173
}
157
174
 
158
175
void
159
 
libxfs_trans_ijoin(xfs_trans_t *tp, xfs_inode_t *ip, uint lock_flags)
 
176
libxfs_trans_ijoin(
 
177
        xfs_trans_t             *tp,
 
178
        xfs_inode_t             *ip,
 
179
        uint                    lock_flags)
160
180
{
161
181
        xfs_inode_log_item_t    *iip;
162
182
 
176
196
}
177
197
 
178
198
void
179
 
libxfs_trans_ihold(xfs_trans_t *tp, xfs_inode_t *ip)
 
199
libxfs_trans_ihold(
 
200
        xfs_trans_t             *tp,
 
201
        xfs_inode_t             *ip)
180
202
{
181
203
        ASSERT(ip->i_transp == tp);
182
204
        ASSERT(ip->i_itemp != NULL);
188
210
}
189
211
 
190
212
void
191
 
libxfs_trans_inode_alloc_buf(xfs_trans_t *tp, xfs_buf_t *bp)
 
213
libxfs_trans_inode_alloc_buf(
 
214
        xfs_trans_t             *tp,
 
215
        xfs_buf_t               *bp)
192
216
{
193
217
        xfs_buf_log_item_t      *bip;
194
218
 
209
233
 */
210
234
void
211
235
xfs_trans_log_inode(
212
 
        xfs_trans_t     *tp,
213
 
        xfs_inode_t     *ip,
214
 
        uint            flags)
 
236
        xfs_trans_t             *tp,
 
237
        xfs_inode_t             *ip,
 
238
        uint                    flags)
215
239
{
216
240
        xfs_log_item_desc_t     *lidp;
217
241
 
242
266
 * This is called to mark bytes first through last inclusive of the given
243
267
 * buffer as needing to be logged when the transaction is committed.
244
268
 * The buffer must already be associated with the given transaction.
245
 
 * 
 
269
 *
246
270
 * First and last are numbers relative to the beginning of this buffer,
247
271
 * so the first byte in the buffer is numbered 0 regardless of the
248
272
 * value of b_blkno.
249
273
 */
250
274
void
251
 
libxfs_trans_log_buf(xfs_trans_t *tp, xfs_buf_t *bp, uint first, uint last)
 
275
libxfs_trans_log_buf(
 
276
        xfs_trans_t             *tp,
 
277
        xfs_buf_t               *bp,
 
278
        uint                    first,
 
279
        uint                    last)
252
280
{
253
281
        xfs_buf_log_item_t      *bip;
254
282
        xfs_log_item_desc_t     *lidp;
271
299
}
272
300
 
273
301
void
274
 
libxfs_trans_brelse(xfs_trans_t *tp, xfs_buf_t *bp)
 
302
libxfs_trans_brelse(
 
303
        xfs_trans_t             *tp,
 
304
        xfs_buf_t               *bp)
275
305
{
276
306
        xfs_buf_log_item_t      *bip;
277
307
        xfs_log_item_desc_t     *lidp;
306
336
}
307
337
 
308
338
void
309
 
libxfs_trans_binval(xfs_trans_t *tp, xfs_buf_t *bp)
 
339
libxfs_trans_binval(
 
340
        xfs_trans_t             *tp,
 
341
        xfs_buf_t               *bp)
310
342
{
311
343
        xfs_log_item_desc_t     *lidp;
312
344
        xfs_buf_log_item_t      *bip;
328
360
}
329
361
 
330
362
void
331
 
libxfs_trans_bjoin(xfs_trans_t *tp, xfs_buf_t *bp)
 
363
libxfs_trans_bjoin(
 
364
        xfs_trans_t             *tp,
 
365
        xfs_buf_t               *bp)
332
366
{
333
367
        xfs_buf_log_item_t      *bip;
334
368
 
344
378
}
345
379
 
346
380
void
347
 
libxfs_trans_bhold(xfs_trans_t *tp, xfs_buf_t *bp)
 
381
libxfs_trans_bhold(
 
382
        xfs_trans_t             *tp,
 
383
        xfs_buf_t               *bp)
348
384
{
349
385
        xfs_buf_log_item_t      *bip;
350
386
 
359
395
}
360
396
 
361
397
xfs_buf_t *
362
 
libxfs_trans_get_buf(xfs_trans_t *tp, dev_t dev, xfs_daddr_t d, int len, uint f)
 
398
libxfs_trans_get_buf(
 
399
        xfs_trans_t             *tp,
 
400
        dev_t                   dev,
 
401
        xfs_daddr_t             d,
 
402
        int                     len,
 
403
        uint                    f)
363
404
{
364
405
        xfs_buf_t               *bp;
365
406
        xfs_buf_log_item_t      *bip;
366
 
        buftarg_t               bdev = { dev };
 
407
        xfs_buftarg_t           bdev = { dev };
367
408
 
368
409
        if (tp == NULL)
369
410
                return libxfs_getbuf(dev, d, len);
398
439
}
399
440
 
400
441
int
401
 
libxfs_trans_read_buf(xfs_mount_t *mp, xfs_trans_t *tp, dev_t dev,
402
 
                        xfs_daddr_t blkno, int len, uint f, xfs_buf_t **bpp)
 
442
libxfs_trans_read_buf(
 
443
        xfs_mount_t             *mp,
 
444
        xfs_trans_t             *tp,
 
445
        dev_t                   dev,
 
446
        xfs_daddr_t             blkno,
 
447
        int                     len,
 
448
        uint                    f,
 
449
        xfs_buf_t               **bpp)
403
450
{
404
451
        xfs_buf_t               *bp;
405
452
        xfs_buf_log_item_t      *bip;
406
453
        int                     error;
407
 
        buftarg_t               bdev = { dev };
 
454
        xfs_buftarg_t           bdev = { dev };
408
455
 
409
456
        if (tp == NULL) {
410
457
                bp = libxfs_getbuf(mp->m_dev, blkno, len);
452
499
 * to the file system's superblock when the transaction commits.
453
500
 * For now, just store the change in the transaction structure.
454
501
 * Mark the transaction structure to indicate that the superblock
455
 
 * needs to be updated before committing. 
 
502
 * needs to be updated before committing.
456
503
 *
457
504
 * Originally derived from xfs_trans_mod_sb().
458
505
 */
459
506
void
460
 
libxfs_trans_mod_sb(xfs_trans_t *tp, uint field, long delta)
 
507
libxfs_trans_mod_sb(
 
508
        xfs_trans_t             *tp,
 
509
        uint                    field,
 
510
        long                    delta)
461
511
{
462
512
        switch (field) {
463
513
        case XFS_TRANS_SB_RES_FDBLOCKS:
488
538
 */
489
539
 
490
540
STATIC void
491
 
inode_item_done(xfs_inode_log_item_t *iip)
 
541
inode_item_done(
 
542
        xfs_inode_log_item_t    *iip)
492
543
{
493
 
        xfs_dinode_t    *dip;
494
 
        xfs_inode_t     *ip;
495
 
        xfs_mount_t     *mp;
496
 
        xfs_buf_t       *bp;
497
 
        int             hold;
498
 
        int             error;
499
 
        extern xfs_zone_t *xfs_ili_zone;
 
544
        xfs_dinode_t            *dip;
 
545
        xfs_inode_t             *ip;
 
546
        xfs_mount_t             *mp;
 
547
        xfs_buf_t               *bp;
 
548
        int                     hold;
 
549
        int                     error;
 
550
        extern xfs_zone_t       *xfs_ili_zone;
500
551
 
501
552
        ip = iip->ili_inode;
502
553
        mp = iip->ili_item.li_mountp;
516
567
         */
517
568
        error = libxfs_itobp(mp, NULL, ip, &dip, &bp, 0);
518
569
        if (error) {
519
 
                fprintf(stderr, "%s: warning - itobp failed (%d)\n",
 
570
                fprintf(stderr, _("%s: warning - itobp failed (%d)\n"),
520
571
                        progname, error);
521
572
                goto ili_done;
522
573
        }
524
575
        XFS_BUF_SET_FSPRIVATE(bp, iip);
525
576
        error = libxfs_iflush_int(ip, bp);
526
577
        if (error) {
527
 
                fprintf(stderr, "%s: warning - iflush_int failed (%d)\n",
 
578
                fprintf(stderr, _("%s: warning - iflush_int failed (%d)\n"),
528
579
                        progname, error);
529
580
                goto ili_done;
530
581
        }
555
606
}
556
607
 
557
608
STATIC void
558
 
buf_item_done(xfs_buf_log_item_t *bip)
 
609
buf_item_done(
 
610
        xfs_buf_log_item_t      *bip)
559
611
{
560
 
        extern xfs_zone_t *xfs_buf_item_zone;
561
 
        xfs_buf_t       *bp;
562
 
        int             hold;
 
612
        xfs_buf_t               *bp;
 
613
        int                     hold;
 
614
        extern xfs_zone_t       *xfs_buf_item_zone;
563
615
 
564
616
        bp = bip->bli_buf;
565
617
        ASSERT(bp != NULL);
587
639
 * item described by the given chunk.
588
640
 */
589
641
static void
590
 
trans_chunk_committed(xfs_log_item_chunk_t *licp)
 
642
trans_chunk_committed(
 
643
        xfs_log_item_chunk_t    *licp)
591
644
{
592
645
        xfs_log_item_desc_t     *lidp;
593
646
        xfs_log_item_t          *lip;
603
656
                else if (lip->li_type == XFS_LI_INODE)
604
657
                        inode_item_done((xfs_inode_log_item_t *)lidp->lid_item);
605
658
                else {
606
 
                        fprintf(stderr, "%s: unrecognised log item type\n",
 
659
                        fprintf(stderr, _("%s: unrecognised log item type\n"),
607
660
                                progname);
608
661
                        ASSERT(0);
609
662
                }
614
667
 * Calls trans_chunk_committed() to process the items in each chunk.
615
668
 */
616
669
static void
617
 
trans_committed(xfs_trans_t *tp)
 
670
trans_committed(
 
671
        xfs_trans_t             *tp)
618
672
{
619
673
        xfs_log_item_chunk_t    *licp;
620
674
        xfs_log_item_chunk_t    *next_licp;
643
697
 * Unlock each item pointed to by a descriptor in the given chunk.
644
698
 * Free descriptors pointing to items which are not dirty if freeing_chunk
645
699
 * is zero. If freeing_chunk is non-zero, then we need to unlock all
646
 
 * items in the chunk.  Return the number of descriptors freed.
 
700
 * items in the chunk.  Return the number of descriptors freed.
647
701
 * Originally based on xfs_trans_unlock_chunk() - adapted for libxfs
648
702
 * transactions though.
649
703
 */
650
704
int
651
705
xfs_trans_unlock_chunk(
652
 
        xfs_log_item_chunk_t    *licp,
 
706
        xfs_log_item_chunk_t    *licp,
653
707
        int                     freeing_chunk,
654
708
        int                     abort,
655
709
        xfs_lsn_t               commit_lsn)     /* nb: unused */
686
740
                        iip->ili_flags &= ~XFS_ILI_HOLD;
687
741
                }
688
742
                else {
689
 
                        fprintf(stderr, "%s: unrecognised log item type\n",
 
743
                        fprintf(stderr, _("%s: unrecognised log item type\n"),
690
744
                                progname);
691
745
                        ASSERT(0);
692
746
                }
711
765
 * Commit the changes represented by this transaction
712
766
 */
713
767
int
714
 
libxfs_trans_commit(xfs_trans_t *tp, uint flags, xfs_lsn_t *commit_lsn_p)
 
768
libxfs_trans_commit(
 
769
        xfs_trans_t     *tp,
 
770
        uint            flags,
 
771
        xfs_lsn_t       *commit_lsn_p)
715
772
{
716
773
        xfs_sb_t        *sbp;
717
774