@@ -331,7 +331,7 @@ static int __fillup_metapath(struct gfs2_inode *ip, struct metapath *mp,
331
331
332
332
if (!dblock )
333
333
break ;
334
- ret = gfs2_meta_indirect_buffer (ip , x + 1 , dblock , & mp -> mp_bh [x + 1 ]);
334
+ ret = gfs2_meta_buffer (ip , GFS2_METATYPE_IN , dblock , & mp -> mp_bh [x + 1 ]);
335
335
if (ret )
336
336
return ret ;
337
337
}
@@ -632,7 +632,7 @@ enum alloc_state {
632
632
};
633
633
634
634
/**
635
- * gfs2_iomap_alloc - Build a metadata tree of the requested height
635
+ * __gfs2_iomap_alloc - Build a metadata tree of the requested height
636
636
* @inode: The GFS2 inode
637
637
* @iomap: The iomap structure
638
638
* @mp: The metapath, with proper height information calculated
@@ -642,7 +642,7 @@ enum alloc_state {
642
642
* ii) Indirect blocks to fill in lower part of the metadata tree
643
643
* iii) Data blocks
644
644
*
645
- * This function is called after gfs2_iomap_get , which works out the
645
+ * This function is called after __gfs2_iomap_get , which works out the
646
646
* total number of blocks which we need via gfs2_alloc_size.
647
647
*
648
648
* We then do the actual allocation asking for an extent at a time (if
@@ -660,8 +660,8 @@ enum alloc_state {
660
660
* Returns: errno on error
661
661
*/
662
662
663
- static int gfs2_iomap_alloc (struct inode * inode , struct iomap * iomap ,
664
- struct metapath * mp )
663
+ static int __gfs2_iomap_alloc (struct inode * inode , struct iomap * iomap ,
664
+ struct metapath * mp )
665
665
{
666
666
struct gfs2_inode * ip = GFS2_I (inode );
667
667
struct gfs2_sbd * sdp = GFS2_SB (inode );
@@ -802,10 +802,10 @@ static u64 gfs2_alloc_size(struct inode *inode, struct metapath *mp, u64 size)
802
802
803
803
/*
804
804
* For writes to stuffed files, this function is called twice via
805
- * gfs2_iomap_get , before and after unstuffing. The size we return the
805
+ * __gfs2_iomap_get , before and after unstuffing. The size we return the
806
806
* first time needs to be large enough to get the reservation and
807
807
* allocation sizes right. The size we return the second time must
808
- * be exact or else gfs2_iomap_alloc won't do the right thing.
808
+ * be exact or else __gfs2_iomap_alloc won't do the right thing.
809
809
*/
810
810
811
811
if (gfs2_is_stuffed (ip ) || mp -> mp_fheight != mp -> mp_aheight ) {
@@ -829,7 +829,7 @@ static u64 gfs2_alloc_size(struct inode *inode, struct metapath *mp, u64 size)
829
829
}
830
830
831
831
/**
832
- * gfs2_iomap_get - Map blocks from an inode to disk blocks
832
+ * __gfs2_iomap_get - Map blocks from an inode to disk blocks
833
833
* @inode: The inode
834
834
* @pos: Starting position in bytes
835
835
* @length: Length to map, in bytes
@@ -839,9 +839,9 @@ static u64 gfs2_alloc_size(struct inode *inode, struct metapath *mp, u64 size)
839
839
*
840
840
* Returns: errno
841
841
*/
842
- static int gfs2_iomap_get (struct inode * inode , loff_t pos , loff_t length ,
843
- unsigned flags , struct iomap * iomap ,
844
- struct metapath * mp )
842
+ static int __gfs2_iomap_get (struct inode * inode , loff_t pos , loff_t length ,
843
+ unsigned flags , struct iomap * iomap ,
844
+ struct metapath * mp )
845
845
{
846
846
struct gfs2_inode * ip = GFS2_I (inode );
847
847
struct gfs2_sbd * sdp = GFS2_SB (inode );
@@ -961,32 +961,6 @@ static int gfs2_iomap_get(struct inode *inode, loff_t pos, loff_t length,
961
961
goto out ;
962
962
}
963
963
964
- /**
965
- * gfs2_lblk_to_dblk - convert logical block to disk block
966
- * @inode: the inode of the file we're mapping
967
- * @lblock: the block relative to the start of the file
968
- * @dblock: the returned dblock, if no error
969
- *
970
- * This function maps a single block from a file logical block (relative to
971
- * the start of the file) to a file system absolute block using iomap.
972
- *
973
- * Returns: the absolute file system block, or an error
974
- */
975
- int gfs2_lblk_to_dblk (struct inode * inode , u32 lblock , u64 * dblock )
976
- {
977
- struct iomap iomap = { };
978
- struct metapath mp = { .mp_aheight = 1 , };
979
- loff_t pos = (loff_t )lblock << inode -> i_blkbits ;
980
- int ret ;
981
-
982
- ret = gfs2_iomap_get (inode , pos , i_blocksize (inode ), 0 , & iomap , & mp );
983
- release_metapath (& mp );
984
- if (ret == 0 )
985
- * dblock = iomap .addr >> inode -> i_blkbits ;
986
-
987
- return ret ;
988
- }
989
-
990
964
static int gfs2_write_lock (struct inode * inode )
991
965
{
992
966
struct gfs2_inode * ip = GFS2_I (inode );
@@ -1109,14 +1083,14 @@ static int gfs2_iomap_begin_write(struct inode *inode, loff_t pos,
1109
1083
if (ret )
1110
1084
goto out_trans_end ;
1111
1085
release_metapath (mp );
1112
- ret = gfs2_iomap_get (inode , iomap -> offset ,
1113
- iomap -> length , flags , iomap , mp );
1086
+ ret = __gfs2_iomap_get (inode , iomap -> offset ,
1087
+ iomap -> length , flags , iomap , mp );
1114
1088
if (ret )
1115
1089
goto out_trans_end ;
1116
1090
}
1117
1091
1118
1092
if (iomap -> type == IOMAP_HOLE ) {
1119
- ret = gfs2_iomap_alloc (inode , iomap , mp );
1093
+ ret = __gfs2_iomap_alloc (inode , iomap , mp );
1120
1094
if (ret ) {
1121
1095
gfs2_trans_end (sdp );
1122
1096
gfs2_inplace_release (ip );
@@ -1168,7 +1142,7 @@ static int gfs2_iomap_begin(struct inode *inode, loff_t pos, loff_t length,
1168
1142
goto out ;
1169
1143
}
1170
1144
1171
- ret = gfs2_iomap_get (inode , pos , length , flags , iomap , & mp );
1145
+ ret = __gfs2_iomap_get (inode , pos , length , flags , iomap , & mp );
1172
1146
if (ret )
1173
1147
goto out_unlock ;
1174
1148
@@ -1290,20 +1264,18 @@ int gfs2_block_map(struct inode *inode, sector_t lblock,
1290
1264
struct gfs2_inode * ip = GFS2_I (inode );
1291
1265
loff_t pos = (loff_t )lblock << inode -> i_blkbits ;
1292
1266
loff_t length = bh_map -> b_size ;
1293
- struct metapath mp = { .mp_aheight = 1 , };
1294
1267
struct iomap iomap = { };
1295
- int flags = create ? IOMAP_WRITE : 0 ;
1296
1268
int ret ;
1297
1269
1298
1270
clear_buffer_mapped (bh_map );
1299
1271
clear_buffer_new (bh_map );
1300
1272
clear_buffer_boundary (bh_map );
1301
1273
trace_gfs2_bmap (ip , bh_map , lblock , create , 1 );
1302
1274
1303
- ret = gfs2_iomap_get ( inode , pos , length , flags , & iomap , & mp );
1304
- if ( create && ! ret && iomap . type == IOMAP_HOLE )
1305
- ret = gfs2_iomap_alloc ( inode , & iomap , & mp );
1306
- release_metapath ( & mp );
1275
+ if (! create )
1276
+ ret = gfs2_iomap_get ( inode , pos , length , & iomap );
1277
+ else
1278
+ ret = gfs2_iomap_alloc ( inode , pos , length , & iomap );
1307
1279
if (ret )
1308
1280
goto out ;
1309
1281
@@ -1324,28 +1296,47 @@ int gfs2_block_map(struct inode *inode, sector_t lblock,
1324
1296
return ret ;
1325
1297
}
1326
1298
1327
- /*
1328
- * Deprecated: do not use in new code
1329
- */
1330
- int gfs2_extent_map (struct inode * inode , u64 lblock , int * new , u64 * dblock , unsigned * extlen )
1299
+ int gfs2_get_extent (struct inode * inode , u64 lblock , u64 * dblock ,
1300
+ unsigned int * extlen )
1331
1301
{
1332
- struct buffer_head bh = { .b_state = 0 , .b_blocknr = 0 };
1302
+ unsigned int blkbits = inode -> i_blkbits ;
1303
+ struct iomap iomap = { };
1304
+ unsigned int len ;
1333
1305
int ret ;
1334
- int create = * new ;
1335
-
1336
- BUG_ON (!extlen );
1337
- BUG_ON (!dblock );
1338
- BUG_ON (!new );
1339
-
1340
- bh .b_size = BIT (inode -> i_blkbits + (create ? 0 : 5 ));
1341
- ret = gfs2_block_map (inode , lblock , & bh , create );
1342
- * extlen = bh .b_size >> inode -> i_blkbits ;
1343
- * dblock = bh .b_blocknr ;
1344
- if (buffer_new (& bh ))
1345
- * new = 1 ;
1346
- else
1347
- * new = 0 ;
1348
- return ret ;
1306
+
1307
+ ret = gfs2_iomap_get (inode , lblock << blkbits , * extlen << blkbits ,
1308
+ & iomap );
1309
+ if (ret )
1310
+ return ret ;
1311
+ if (iomap .type != IOMAP_MAPPED )
1312
+ return - EIO ;
1313
+ * dblock = iomap .addr >> blkbits ;
1314
+ len = iomap .length >> blkbits ;
1315
+ if (len < * extlen )
1316
+ * extlen = len ;
1317
+ return 0 ;
1318
+ }
1319
+
1320
+ int gfs2_alloc_extent (struct inode * inode , u64 lblock , u64 * dblock ,
1321
+ unsigned int * extlen , bool * new )
1322
+ {
1323
+ unsigned int blkbits = inode -> i_blkbits ;
1324
+ struct iomap iomap = { };
1325
+ unsigned int len ;
1326
+ int ret ;
1327
+
1328
+ ret = gfs2_iomap_alloc (inode , lblock << blkbits , * extlen << blkbits ,
1329
+ & iomap );
1330
+ if (ret )
1331
+ return ret ;
1332
+ if (iomap .type != IOMAP_MAPPED )
1333
+ return - EIO ;
1334
+ * dblock = iomap .addr >> blkbits ;
1335
+ len = iomap .length >> blkbits ;
1336
+ if (len < * extlen )
1337
+ * extlen = len ;
1338
+ * new = iomap .flags & IOMAP_F_NEW ;
1339
+ return 0 ;
1349
1340
}
1350
1341
1351
1342
/*
@@ -1461,23 +1452,34 @@ static int trunc_start(struct inode *inode, u64 newsize)
1461
1452
return error ;
1462
1453
}
1463
1454
1464
- int gfs2_iomap_get_alloc (struct inode * inode , loff_t pos , loff_t length ,
1465
- struct iomap * iomap )
1455
+ int gfs2_iomap_get (struct inode * inode , loff_t pos , loff_t length ,
1456
+ struct iomap * iomap )
1466
1457
{
1467
1458
struct metapath mp = { .mp_aheight = 1 , };
1468
1459
int ret ;
1469
1460
1470
- ret = gfs2_iomap_get (inode , pos , length , IOMAP_WRITE , iomap , & mp );
1461
+ ret = __gfs2_iomap_get (inode , pos , length , 0 , iomap , & mp );
1462
+ release_metapath (& mp );
1463
+ return ret ;
1464
+ }
1465
+
1466
+ int gfs2_iomap_alloc (struct inode * inode , loff_t pos , loff_t length ,
1467
+ struct iomap * iomap )
1468
+ {
1469
+ struct metapath mp = { .mp_aheight = 1 , };
1470
+ int ret ;
1471
+
1472
+ ret = __gfs2_iomap_get (inode , pos , length , IOMAP_WRITE , iomap , & mp );
1471
1473
if (!ret && iomap -> type == IOMAP_HOLE )
1472
- ret = gfs2_iomap_alloc (inode , iomap , & mp );
1474
+ ret = __gfs2_iomap_alloc (inode , iomap , & mp );
1473
1475
release_metapath (& mp );
1474
1476
return ret ;
1475
1477
}
1476
1478
1477
1479
/**
1478
1480
* sweep_bh_for_rgrps - find an rgrp in a meta buffer and free blocks therein
1479
1481
* @ip: inode
1480
- * @rg_gh : holder of resource group glock
1482
+ * @rd_gh : holder of resource group glock
1481
1483
* @bh: buffer head to sweep
1482
1484
* @start: starting point in bh
1483
1485
* @end: end point in bh
@@ -1658,8 +1660,11 @@ static bool mp_eq_to_hgt(struct metapath *mp, __u16 *list, unsigned int h)
1658
1660
1659
1661
/**
1660
1662
* find_nonnull_ptr - find a non-null pointer given a metapath and height
1663
+ * @sdp: The superblock
1661
1664
* @mp: starting metapath
1662
1665
* @h: desired height to search
1666
+ * @end_list: See punch_hole().
1667
+ * @end_aligned: See punch_hole().
1663
1668
*
1664
1669
* Assumes the metapath is valid (with buffers) out to height h.
1665
1670
* Returns: true if a non-null pointer was found in the metapath buffer
@@ -2519,7 +2524,6 @@ int __gfs2_punch_hole(struct file *file, loff_t offset, loff_t length)
2519
2524
static int gfs2_map_blocks (struct iomap_writepage_ctx * wpc , struct inode * inode ,
2520
2525
loff_t offset )
2521
2526
{
2522
- struct metapath mp = { .mp_aheight = 1 , };
2523
2527
int ret ;
2524
2528
2525
2529
if (WARN_ON_ONCE (gfs2_is_stuffed (GFS2_I (inode ))))
@@ -2530,8 +2534,7 @@ static int gfs2_map_blocks(struct iomap_writepage_ctx *wpc, struct inode *inode,
2530
2534
return 0 ;
2531
2535
2532
2536
memset (& wpc -> iomap , 0 , sizeof (wpc -> iomap ));
2533
- ret = gfs2_iomap_get (inode , offset , INT_MAX , 0 , & wpc -> iomap , & mp );
2534
- release_metapath (& mp );
2537
+ ret = gfs2_iomap_get (inode , offset , INT_MAX , & wpc -> iomap );
2535
2538
return ret ;
2536
2539
}
2537
2540
0 commit comments