2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public
4 * License v2 as published by the Free Software Foundation.
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 * General Public License for more details.
11 * You should have received a copy of the GNU General Public
12 * License along with this program; if not, write to the
13 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
14 * Boston, MA 021110-1307, USA.
17 #include "kerncompat.h"
18 #include "transaction.h"
22 struct btrfs_trans_handle* btrfs_start_transaction(struct btrfs_root *root,
25 struct btrfs_fs_info *fs_info = root->fs_info;
26 struct btrfs_trans_handle *h = kzalloc(sizeof(*h), GFP_NOFS);
29 return ERR_PTR(-ENOMEM);
30 if (root->commit_root) {
31 error("commit_root aleady set when starting transaction");
33 return ERR_PTR(-EINVAL);
35 if (fs_info->running_transaction) {
36 error("attempt to start transaction over already running one");
38 return ERR_PTR(-EINVAL);
40 fs_info->running_transaction = h;
41 fs_info->generation++;
42 h->transid = fs_info->generation;
43 h->blocks_reserved = num_blocks;
44 root->last_trans = h->transid;
45 root->commit_root = root->node;
46 extent_buffer_get(root->node);