super.c (b18c6685810af8e6763760711aece31ccc7a8ea8) super.c (70b2befd0c8a4064715d8b340270650cc9d15af8)
1#include <linux/module.h>
2#include <linux/buffer_head.h>
3#include <linux/fs.h>
4#include <linux/pagemap.h>
5#include <linux/highmem.h>
6#include <linux/time.h>
7#include <linux/init.h>
8#include <linux/string.h>

--- 510 unchanged lines hidden (view full) ---

519 struct btrfs_path *path;
520 int ret;
521 u32 nritems;
522 struct btrfs_leaf *leaf;
523 int slot;
524 int advance;
525 unsigned char d_type = DT_UNKNOWN;
526 int over = 0;
1#include <linux/module.h>
2#include <linux/buffer_head.h>
3#include <linux/fs.h>
4#include <linux/pagemap.h>
5#include <linux/highmem.h>
6#include <linux/time.h>
7#include <linux/init.h>
8#include <linux/string.h>

--- 510 unchanged lines hidden (view full) ---

519 struct btrfs_path *path;
520 int ret;
521 u32 nritems;
522 struct btrfs_leaf *leaf;
523 int slot;
524 int advance;
525 unsigned char d_type = DT_UNKNOWN;
526 int over = 0;
527 int key_type = BTRFS_DIR_INDEX_KEY;
527 int key_type = BTRFS_DIR_ITEM_KEY;
528
529 /* FIXME, use a real flag for deciding about the key type */
530 if (root->fs_info->tree_root == root)
531 key_type = BTRFS_DIR_ITEM_KEY;
532 mutex_lock(&root->fs_info->fs_mutex);
533 key.objectid = inode->i_ino;
534 key.flags = 0;
535 btrfs_set_key_type(&key, key_type);

--- 20 unchanged lines hidden (view full) ---

556 slot++;
557 path->slots[0]++;
558 }
559 }
560 advance = 1;
561 item = leaf->items + slot;
562 if (btrfs_disk_key_objectid(&item->key) != key.objectid)
563 break;
528
529 /* FIXME, use a real flag for deciding about the key type */
530 if (root->fs_info->tree_root == root)
531 key_type = BTRFS_DIR_ITEM_KEY;
532 mutex_lock(&root->fs_info->fs_mutex);
533 key.objectid = inode->i_ino;
534 key.flags = 0;
535 btrfs_set_key_type(&key, key_type);

--- 20 unchanged lines hidden (view full) ---

556 slot++;
557 path->slots[0]++;
558 }
559 }
560 advance = 1;
561 item = leaf->items + slot;
562 if (btrfs_disk_key_objectid(&item->key) != key.objectid)
563 break;
564 if (key_type == BTRFS_DIR_INDEX_KEY &&
565 btrfs_disk_key_offset(&item->key) > root->highest_inode)
566 break;
567 if (btrfs_disk_key_type(&item->key) != key_type)
568 continue;
569 if (btrfs_disk_key_offset(&item->key) < filp->f_pos)
570 continue;
571 filp->f_pos = btrfs_disk_key_offset(&item->key);
572 advance = 1;
573 di = btrfs_item_ptr(leaf, slot, struct btrfs_dir_item);
574 over = filldir(dirent, (const char *)(di + 1),

--- 539 unchanged lines hidden (view full) ---

1114 set_buffer_new(result);
1115 map_bh(result, inode->i_sb, blocknr);
1116
1117 btrfs_map_bh_to_logical(root, result, blocknr);
1118#endif
1119out:
1120 btrfs_release_path(root, path);
1121 btrfs_free_path(path);
564 if (btrfs_disk_key_type(&item->key) != key_type)
565 continue;
566 if (btrfs_disk_key_offset(&item->key) < filp->f_pos)
567 continue;
568 filp->f_pos = btrfs_disk_key_offset(&item->key);
569 advance = 1;
570 di = btrfs_item_ptr(leaf, slot, struct btrfs_dir_item);
571 over = filldir(dirent, (const char *)(di + 1),

--- 539 unchanged lines hidden (view full) ---

1111 set_buffer_new(result);
1112 map_bh(result, inode->i_sb, blocknr);
1113
1114 btrfs_map_bh_to_logical(root, result, blocknr);
1115#endif
1116out:
1117 btrfs_release_path(root, path);
1118 btrfs_free_path(path);
1122printk("mapping iblock %lu to %lu\n", iblock, result->b_blocknr);
1123 if (trans)
1124 btrfs_end_transaction(trans, root);
1125 return err;
1126}
1127
1128static int btrfs_get_block(struct inode *inode, sector_t iblock,
1129 struct buffer_head *result, int create)
1130{

--- 97 unchanged lines hidden (view full) ---

1228 page_cache_release(pages[i]);
1229 }
1230}
1231static int dirty_and_release_pages(struct btrfs_trans_handle *trans,
1232 struct btrfs_root *root,
1233 struct file *file,
1234 struct page **pages,
1235 size_t num_pages,
1119 if (trans)
1120 btrfs_end_transaction(trans, root);
1121 return err;
1122}
1123
1124static int btrfs_get_block(struct inode *inode, sector_t iblock,
1125 struct buffer_head *result, int create)
1126{

--- 97 unchanged lines hidden (view full) ---

1224 page_cache_release(pages[i]);
1225 }
1226}
1227static int dirty_and_release_pages(struct btrfs_trans_handle *trans,
1228 struct btrfs_root *root,
1229 struct file *file,
1230 struct page **pages,
1231 size_t num_pages,
1236 u64 extent_offset,
1237 loff_t pos,
1238 size_t write_bytes)
1239{
1240 int i;
1241 int offset;
1242 int err = 0;
1243 int ret;
1244 int this_write;
1245 struct inode *inode = file->f_path.dentry->d_inode;
1246
1247 for (i = 0; i < num_pages; i++) {
1248 offset = pos & (PAGE_CACHE_SIZE -1);
1249 this_write = min(PAGE_CACHE_SIZE - offset, write_bytes);
1250 /* FIXME, one block at a time */
1251
1252 mutex_lock(&root->fs_info->fs_mutex);
1253 trans = btrfs_start_transaction(root, 1);
1254 btrfs_csum_file_block(trans, root, inode->i_ino,
1255 pages[i]->index << PAGE_CACHE_SHIFT,
1232 loff_t pos,
1233 size_t write_bytes)
1234{
1235 int i;
1236 int offset;
1237 int err = 0;
1238 int ret;
1239 int this_write;
1240 struct inode *inode = file->f_path.dentry->d_inode;
1241
1242 for (i = 0; i < num_pages; i++) {
1243 offset = pos & (PAGE_CACHE_SIZE -1);
1244 this_write = min(PAGE_CACHE_SIZE - offset, write_bytes);
1245 /* FIXME, one block at a time */
1246
1247 mutex_lock(&root->fs_info->fs_mutex);
1248 trans = btrfs_start_transaction(root, 1);
1249 btrfs_csum_file_block(trans, root, inode->i_ino,
1250 pages[i]->index << PAGE_CACHE_SHIFT,
1256 extent_offset,
1257 kmap(pages[i]), PAGE_CACHE_SIZE);
1258 kunmap(pages[i]);
1259 SetPageChecked(pages[i]);
1260 ret = btrfs_end_transaction(trans, root);
1261 BUG_ON(ret);
1262 mutex_unlock(&root->fs_info->fs_mutex);
1263
1264 ret = nobh_commit_write(file, pages[i], offset,

--- 5 unchanged lines hidden (view full) ---

1270 }
1271 WARN_ON(this_write > write_bytes);
1272 write_bytes -= this_write;
1273 }
1274failed:
1275 return err;
1276}
1277
1251 kmap(pages[i]), PAGE_CACHE_SIZE);
1252 kunmap(pages[i]);
1253 SetPageChecked(pages[i]);
1254 ret = btrfs_end_transaction(trans, root);
1255 BUG_ON(ret);
1256 mutex_unlock(&root->fs_info->fs_mutex);
1257
1258 ret = nobh_commit_write(file, pages[i], offset,

--- 5 unchanged lines hidden (view full) ---

1264 }
1265 WARN_ON(this_write > write_bytes);
1266 write_bytes -= this_write;
1267 }
1268failed:
1269 return err;
1270}
1271
1278static int drop_csums(struct btrfs_trans_handle *trans,
1279 struct btrfs_root *root,
1280 struct inode *inode,
1281 u64 start, u64 end)
1282{
1283 struct btrfs_path *path;
1284 struct btrfs_leaf *leaf;
1285 struct btrfs_key key;
1286 int slot;
1287 struct btrfs_csum_item *item;
1288 char *old_block = NULL;
1289 u64 cur = start;
1290 u64 found_end;
1291 u64 num_csums;
1292 u64 item_size;
1293 int ret;
1294
1295 path = btrfs_alloc_path();
1296 if (!path)
1297 return -ENOMEM;
1298 while(cur < end) {
1299 item = btrfs_lookup_csum(trans, root, path,
1300 inode->i_ino, cur, 1);
1301 if (IS_ERR(item)) {
1302 cur += root->blocksize;
1303 continue;
1304 }
1305 leaf = btrfs_buffer_leaf(path->nodes[0]);
1306 slot = path->slots[0];
1307 btrfs_disk_key_to_cpu(&key, &leaf->items[slot].key);
1308 item_size = btrfs_item_size(leaf->items + slot);
1309 num_csums = item_size / sizeof(struct btrfs_csum_item);
1310 found_end = key.offset + (num_csums << inode->i_blkbits);
1311 cur = found_end;
1312
1313 if (found_end > end) {
1314 char *src;
1315 old_block = kmalloc(root->blocksize, GFP_NOFS);
1316 src = btrfs_item_ptr(leaf, slot, char);
1317 memcpy(old_block, src, item_size);
1318 }
1319 if (key.offset < start) {
1320 u64 new_size = (start - key.offset) >>
1321 inode->i_blkbits;
1322 new_size *= sizeof(struct btrfs_csum_item);
1323 ret = btrfs_truncate_item(trans, root, path, new_size);
1324 BUG_ON(ret);
1325 } else {
1326 btrfs_del_item(trans, root, path);
1327 }
1328 btrfs_release_path(root, path);
1329 if (found_end > end) {
1330 char *dst;
1331 int i;
1332 int new_size;
1333
1334 num_csums = (found_end - end) >> inode->i_blkbits;
1335 new_size = num_csums * sizeof(struct btrfs_csum_item);
1336 key.offset = end;
1337 ret = btrfs_insert_empty_item(trans, root, path,
1338 &key, new_size);
1339 BUG_ON(ret);
1340 dst = btrfs_item_ptr(btrfs_buffer_leaf(path->nodes[0]),
1341 path->slots[0], char);
1342 memcpy(dst, old_block + item_size - new_size,
1343 new_size);
1344 item = (struct btrfs_csum_item *)dst;
1345 for (i = 0; i < num_csums; i++) {
1346 btrfs_set_csum_extent_offset(item, end);
1347 item++;
1348 }
1349 mark_buffer_dirty(path->nodes[0]);
1350 kfree(old_block);
1351 break;
1352 }
1353 }
1354 btrfs_free_path(path);
1355 return 0;
1356}
1357
1358static int drop_extents(struct btrfs_trans_handle *trans,
1359 struct btrfs_root *root,
1360 struct inode *inode,
1361 u64 start, u64 end)
1362{
1363 int ret;
1364 struct btrfs_key key;
1365 struct btrfs_leaf *leaf;

--- 5 unchanged lines hidden (view full) ---

1371 struct btrfs_path *path;
1372 u64 search_start = start;
1373 int bookend;
1374
1375 path = btrfs_alloc_path();
1376 if (!path)
1377 return -ENOMEM;
1378search_again:
1272static int drop_extents(struct btrfs_trans_handle *trans,
1273 struct btrfs_root *root,
1274 struct inode *inode,
1275 u64 start, u64 end)
1276{
1277 int ret;
1278 struct btrfs_key key;
1279 struct btrfs_leaf *leaf;

--- 5 unchanged lines hidden (view full) ---

1285 struct btrfs_path *path;
1286 u64 search_start = start;
1287 int bookend;
1288
1289 path = btrfs_alloc_path();
1290 if (!path)
1291 return -ENOMEM;
1292search_again:
1379printk("drop extent inode %lu start %Lu end %Lu\n", inode->i_ino, start, end);
1380 ret = btrfs_lookup_file_extent(trans, root, path, inode->i_ino,
1381 search_start, -1);
1293 ret = btrfs_lookup_file_extent(trans, root, path, inode->i_ino,
1294 search_start, -1);
1382 if (ret != 0) {
1383printk("lookup failed\n");
1295 if (ret < 0)
1384 goto out;
1296 goto out;
1297 if (ret > 0) {
1298 if (path->slots[0] == 0) {
1299 ret = -ENOENT;
1300 goto out;
1301 }
1302 path->slots[0]--;
1385 }
1386 while(1) {
1387 keep = 0;
1388 bookend = 0;
1389 leaf = btrfs_buffer_leaf(path->nodes[0]);
1390 slot = path->slots[0];
1391 btrfs_disk_key_to_cpu(&key, &leaf->items[slot].key);
1392
1303 }
1304 while(1) {
1305 keep = 0;
1306 bookend = 0;
1307 leaf = btrfs_buffer_leaf(path->nodes[0]);
1308 slot = path->slots[0];
1309 btrfs_disk_key_to_cpu(&key, &leaf->items[slot].key);
1310
1393printk("found key %Lu %Lu %u\n", key.objectid, key.offset, key.flags);
1394
1395 extent = btrfs_item_ptr(leaf, slot,
1396 struct btrfs_file_extent_item);
1397 extent_end = key.offset +
1398 (btrfs_file_extent_num_blocks(extent) <<
1399 inode->i_blkbits);
1311 extent = btrfs_item_ptr(leaf, slot,
1312 struct btrfs_file_extent_item);
1313 extent_end = key.offset +
1314 (btrfs_file_extent_num_blocks(extent) <<
1315 inode->i_blkbits);
1400printk("extent end is %Lu\n", extent_end);
1401 if (key.offset >= end || key.objectid != inode->i_ino) {
1402 ret = 0;
1403 goto out;
1404 }
1405 if (btrfs_key_type(&key) != BTRFS_EXTENT_DATA_KEY)
1406 goto next_leaf;
1407
1408 if (end < extent_end && end >= key.offset) {

--- 6 unchanged lines hidden (view full) ---

1415 }
1416
1417 if (start > key.offset) {
1418 u64 new_num;
1419 /* truncate existing extent */
1420 keep = 1;
1421 WARN_ON(start & (root->blocksize - 1));
1422 new_num = (start - key.offset) >> inode->i_blkbits;
1316 if (key.offset >= end || key.objectid != inode->i_ino) {
1317 ret = 0;
1318 goto out;
1319 }
1320 if (btrfs_key_type(&key) != BTRFS_EXTENT_DATA_KEY)
1321 goto next_leaf;
1322
1323 if (end < extent_end && end >= key.offset) {

--- 6 unchanged lines hidden (view full) ---

1330 }
1331
1332 if (start > key.offset) {
1333 u64 new_num;
1334 /* truncate existing extent */
1335 keep = 1;
1336 WARN_ON(start & (root->blocksize - 1));
1337 new_num = (start - key.offset) >> inode->i_blkbits;
1423printk("truncating existing extent, was %Lu ", btrfs_file_extent_num_blocks(extent));
1424 btrfs_set_file_extent_num_blocks(extent, new_num);
1338 btrfs_set_file_extent_num_blocks(extent, new_num);
1425printk("now %Lu\n", btrfs_file_extent_num_blocks(extent));
1426
1427 mark_buffer_dirty(path->nodes[0]);
1428 }
1429 if (!keep) {
1430 u64 disk_blocknr;
1431 u64 disk_num_blocks;
1339 mark_buffer_dirty(path->nodes[0]);
1340 }
1341 if (!keep) {
1342 u64 disk_blocknr;
1343 u64 disk_num_blocks;
1432printk("del old\n");
1433 disk_blocknr = btrfs_file_extent_disk_blocknr(extent);
1434 disk_num_blocks =
1435 btrfs_file_extent_disk_num_blocks(extent);
1436 search_start = key.offset +
1437 (btrfs_file_extent_num_blocks(extent) <<
1438 inode->i_blkbits);
1439 ret = btrfs_del_item(trans, root, path);
1440 BUG_ON(ret);

--- 8 unchanged lines hidden (view full) ---

1449 goto out;
1450 }
1451 if (!bookend)
1452 goto search_again;
1453 }
1454 if (bookend) {
1455 /* create bookend */
1456 struct btrfs_key ins;
1344 disk_blocknr = btrfs_file_extent_disk_blocknr(extent);
1345 disk_num_blocks =
1346 btrfs_file_extent_disk_num_blocks(extent);
1347 search_start = key.offset +
1348 (btrfs_file_extent_num_blocks(extent) <<
1349 inode->i_blkbits);
1350 ret = btrfs_del_item(trans, root, path);
1351 BUG_ON(ret);

--- 8 unchanged lines hidden (view full) ---

1360 goto out;
1361 }
1362 if (!bookend)
1363 goto search_again;
1364 }
1365 if (bookend) {
1366 /* create bookend */
1367 struct btrfs_key ins;
1457printk("bookend! extent end %Lu\n", extent_end);
1458 ins.objectid = inode->i_ino;
1459 ins.offset = end;
1460 ins.flags = 0;
1461 btrfs_set_key_type(&ins, BTRFS_EXTENT_DATA_KEY);
1462
1463 btrfs_release_path(root, path);
1368 ins.objectid = inode->i_ino;
1369 ins.offset = end;
1370 ins.flags = 0;
1371 btrfs_set_key_type(&ins, BTRFS_EXTENT_DATA_KEY);
1372
1373 btrfs_release_path(root, path);
1464 ret = drop_csums(trans, root, inode, start, end);
1465 BUG_ON(ret);
1466 ret = btrfs_insert_empty_item(trans, root, path, &ins,
1467 sizeof(*extent));
1468 BUG_ON(ret);
1469 extent = btrfs_item_ptr(
1470 btrfs_buffer_leaf(path->nodes[0]),
1471 path->slots[0],
1472 struct btrfs_file_extent_item);
1473 btrfs_set_file_extent_disk_blocknr(extent,

--- 7 unchanged lines hidden (view full) ---

1481 WARN_ON(btrfs_file_extent_num_blocks(&old) <
1482 (end - key.offset) >> inode->i_blkbits);
1483 btrfs_set_file_extent_num_blocks(extent,
1484 btrfs_file_extent_num_blocks(&old) -
1485 ((end - key.offset) >> inode->i_blkbits));
1486
1487 btrfs_set_file_extent_generation(extent,
1488 btrfs_file_extent_generation(&old));
1374 ret = btrfs_insert_empty_item(trans, root, path, &ins,
1375 sizeof(*extent));
1376 BUG_ON(ret);
1377 extent = btrfs_item_ptr(
1378 btrfs_buffer_leaf(path->nodes[0]),
1379 path->slots[0],
1380 struct btrfs_file_extent_item);
1381 btrfs_set_file_extent_disk_blocknr(extent,

--- 7 unchanged lines hidden (view full) ---

1389 WARN_ON(btrfs_file_extent_num_blocks(&old) <
1390 (end - key.offset) >> inode->i_blkbits);
1391 btrfs_set_file_extent_num_blocks(extent,
1392 btrfs_file_extent_num_blocks(&old) -
1393 ((end - key.offset) >> inode->i_blkbits));
1394
1395 btrfs_set_file_extent_generation(extent,
1396 btrfs_file_extent_generation(&old));
1489printk("new bookend at offset %Lu, file_extent_offset %Lu, file_extent_num_blocks %Lu\n", end, btrfs_file_extent_offset(extent), btrfs_file_extent_num_blocks(extent));
1490 btrfs_mark_buffer_dirty(path->nodes[0]);
1491 ret = 0;
1397 btrfs_mark_buffer_dirty(path->nodes[0]);
1398 ret = 0;
1492 goto out_nocsum;
1399 goto out;
1493 }
1494next_leaf:
1495 if (slot >= btrfs_header_nritems(&leaf->header) - 1) {
1496 ret = btrfs_next_leaf(root, path);
1497 if (ret) {
1498 ret = 0;
1499 goto out;
1500 }
1501 } else {
1502 path->slots[0]++;
1503 }
1504 }
1505
1506out:
1400 }
1401next_leaf:
1402 if (slot >= btrfs_header_nritems(&leaf->header) - 1) {
1403 ret = btrfs_next_leaf(root, path);
1404 if (ret) {
1405 ret = 0;
1406 goto out;
1407 }
1408 } else {
1409 path->slots[0]++;
1410 }
1411 }
1412
1413out:
1507 ret = drop_csums(trans, root, inode, start, end);
1508 BUG_ON(ret);
1509
1510out_nocsum:
1511 btrfs_free_path(path);
1512 return ret;
1513}
1514
1515static int prepare_pages(struct btrfs_root *root,
1516 struct file *file,
1517 struct page **pages,
1518 size_t num_pages,

--- 32 unchanged lines hidden (view full) ---

1551 lock_page(pages[i]);
1552 }
1553#endif
1554 create_empty_buffers(pages[i], root->fs_info->sb->s_blocksize,
1555 (1 << BH_Uptodate));
1556 head = page_buffers(pages[i]);
1557 bh = head;
1558 do {
1414 btrfs_free_path(path);
1415 return ret;
1416}
1417
1418static int prepare_pages(struct btrfs_root *root,
1419 struct file *file,
1420 struct page **pages,
1421 size_t num_pages,

--- 32 unchanged lines hidden (view full) ---

1454 lock_page(pages[i]);
1455 }
1456#endif
1457 create_empty_buffers(pages[i], root->fs_info->sb->s_blocksize,
1458 (1 << BH_Uptodate));
1459 head = page_buffers(pages[i]);
1460 bh = head;
1461 do {
1559printk("mapping page %lu to block %Lu\n", pages[i]->index, alloc_extent_start);
1560 err = btrfs_map_bh_to_logical(root, bh,
1561 alloc_extent_start);
1562 BUG_ON(err);
1563 if (err)
1564 goto failed_truncate;
1565 bh = bh->b_this_page;
1566 alloc_extent_start++;
1567 } while (bh != head);

--- 24 unchanged lines hidden (view full) ---

1592 struct inode *inode = file->f_path.dentry->d_inode;
1593 struct btrfs_root *root = BTRFS_I(inode)->root;
1594 struct page *pages[8];
1595 unsigned long first_index;
1596 unsigned long last_index;
1597 u64 start_pos;
1598 u64 num_blocks;
1599 u64 alloc_extent_start;
1462 err = btrfs_map_bh_to_logical(root, bh,
1463 alloc_extent_start);
1464 BUG_ON(err);
1465 if (err)
1466 goto failed_truncate;
1467 bh = bh->b_this_page;
1468 alloc_extent_start++;
1469 } while (bh != head);

--- 24 unchanged lines hidden (view full) ---

1494 struct inode *inode = file->f_path.dentry->d_inode;
1495 struct btrfs_root *root = BTRFS_I(inode)->root;
1496 struct page *pages[8];
1497 unsigned long first_index;
1498 unsigned long last_index;
1499 u64 start_pos;
1500 u64 num_blocks;
1501 u64 alloc_extent_start;
1600 u64 orig_extent_start;
1601 struct btrfs_trans_handle *trans;
1602 struct btrfs_key ins;
1603
1604 if (file->f_flags & O_DIRECT)
1605 return -EINVAL;
1606 pos = *ppos;
1607
1608 start_pos = pos & ~(root->blocksize - 1);

--- 26 unchanged lines hidden (view full) ---

1635 goto out_unlock;
1636 }
1637 if (start_pos < inode->i_size) {
1638 ret = drop_extents(trans, root, inode,
1639 start_pos,
1640 (pos + count + root->blocksize -1) &
1641 ~(root->blocksize - 1));
1642 }
1502 struct btrfs_trans_handle *trans;
1503 struct btrfs_key ins;
1504
1505 if (file->f_flags & O_DIRECT)
1506 return -EINVAL;
1507 pos = *ppos;
1508
1509 start_pos = pos & ~(root->blocksize - 1);

--- 26 unchanged lines hidden (view full) ---

1536 goto out_unlock;
1537 }
1538 if (start_pos < inode->i_size) {
1539 ret = drop_extents(trans, root, inode,
1540 start_pos,
1541 (pos + count + root->blocksize -1) &
1542 ~(root->blocksize - 1));
1543 }
1643 orig_extent_start = start_pos;
1644 ret = btrfs_alloc_extent(trans, root, num_blocks, 1,
1645 (u64)-1, &ins);
1646 BUG_ON(ret);
1647 ret = btrfs_insert_file_extent(trans, root, inode->i_ino,
1648 start_pos, ins.objectid, ins.offset);
1649 BUG_ON(ret);
1650 alloc_extent_start = ins.objectid;
1651 ret = btrfs_end_transaction(trans, root);
1652 mutex_unlock(&root->fs_info->fs_mutex);
1653
1654 while(count > 0) {
1655 size_t offset = pos & (PAGE_CACHE_SIZE - 1);
1656 size_t write_bytes = min(count, PAGE_CACHE_SIZE - offset);
1657 size_t num_pages = (write_bytes + PAGE_CACHE_SIZE - 1) >>
1658 PAGE_CACHE_SHIFT;
1544 ret = btrfs_alloc_extent(trans, root, num_blocks, 1,
1545 (u64)-1, &ins);
1546 BUG_ON(ret);
1547 ret = btrfs_insert_file_extent(trans, root, inode->i_ino,
1548 start_pos, ins.objectid, ins.offset);
1549 BUG_ON(ret);
1550 alloc_extent_start = ins.objectid;
1551 ret = btrfs_end_transaction(trans, root);
1552 mutex_unlock(&root->fs_info->fs_mutex);
1553
1554 while(count > 0) {
1555 size_t offset = pos & (PAGE_CACHE_SIZE - 1);
1556 size_t write_bytes = min(count, PAGE_CACHE_SIZE - offset);
1557 size_t num_pages = (write_bytes + PAGE_CACHE_SIZE - 1) >>
1558 PAGE_CACHE_SHIFT;
1659printk("num_pages is %lu\n", num_pages);
1660
1661 memset(pages, 0, sizeof(pages));
1662 ret = prepare_pages(root, file, pages, num_pages,
1663 pos, first_index, last_index,
1664 write_bytes, alloc_extent_start);
1665 BUG_ON(ret);
1666
1667 /* FIXME blocks != pagesize */
1668 alloc_extent_start += num_pages;
1669 ret = btrfs_copy_from_user(pos, num_pages,
1670 write_bytes, pages, buf);
1671 BUG_ON(ret);
1672
1559
1560 memset(pages, 0, sizeof(pages));
1561 ret = prepare_pages(root, file, pages, num_pages,
1562 pos, first_index, last_index,
1563 write_bytes, alloc_extent_start);
1564 BUG_ON(ret);
1565
1566 /* FIXME blocks != pagesize */
1567 alloc_extent_start += num_pages;
1568 ret = btrfs_copy_from_user(pos, num_pages,
1569 write_bytes, pages, buf);
1570 BUG_ON(ret);
1571
1673printk("2num_pages is %lu\n", num_pages);
1674 ret = dirty_and_release_pages(NULL, root, file, pages,
1572 ret = dirty_and_release_pages(NULL, root, file, pages,
1675 num_pages, orig_extent_start,
1676 pos, write_bytes);
1573 num_pages, pos, write_bytes);
1677 BUG_ON(ret);
1678 btrfs_drop_pages(pages, num_pages);
1679
1680 buf += write_bytes;
1681 count -= write_bytes;
1682 pos += write_bytes;
1683 num_written += write_bytes;
1684

--- 752 unchanged lines hidden ---
1574 BUG_ON(ret);
1575 btrfs_drop_pages(pages, num_pages);
1576
1577 buf += write_bytes;
1578 count -= write_bytes;
1579 pos += write_bytes;
1580 num_written += write_bytes;
1581

--- 752 unchanged lines hidden ---