2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
7 * of the GNU General Public License v.2.
10 #include <linux/sched.h>
11 #include <linux/slab.h>
12 #include <linux/spinlock.h>
13 #include <linux/completion.h>
14 #include <linux/buffer_head.h>
15 #include <asm/semaphore.h>
30 /* A single transaction needs to add the structs to rindex and make the
33 int gfs2_resize_add_rgrps(struct gfs2_sbd *sdp, char __user *buf,
36 unsigned int num = size / sizeof(struct gfs2_rindex);
37 struct gfs2_inode *ip = sdp->sd_rindex;
38 struct gfs2_alloc *al = NULL;
39 struct gfs2_holder i_gh;
40 unsigned int data_blocks, ind_blocks;
45 gfs2_write_calc_reserv(ip, size, &data_blocks, &ind_blocks);
47 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE,
48 LM_FLAG_PRIORITY | GL_SYNC, &i_gh);
52 if (!gfs2_is_jdata(ip)) {
53 gfs2_consist_inode(ip);
58 error = gfs2_write_alloc_required(ip, ip->i_di.di_size, size,
64 al = gfs2_alloc_get(ip);
66 al->al_requested = data_blocks + ind_blocks;
68 error = gfs2_inplace_reserve(ip);
72 error = gfs2_trans_begin(sdp,
73 al->al_rgd->rd_ri.ri_length +
74 data_blocks + ind_blocks +
75 RES_DINODE + RES_STATFS, 0);
79 error = gfs2_trans_begin(sdp, data_blocks +
80 RES_DINODE + RES_STATFS, 0);
85 for (x = 0; x < num; x++) {
86 struct gfs2_rindex ri;
87 char ri_buf[sizeof(struct gfs2_rindex)];
89 error = copy_from_user(&ri, buf, sizeof(struct gfs2_rindex));
94 gfs2_rindex_out(&ri, ri_buf);
96 error = gfs2_jdata_write_mem(ip, ri_buf, ip->i_di.di_size,
97 sizeof(struct gfs2_rindex));
100 gfs2_assert_withdraw(sdp, error == sizeof(struct gfs2_rindex));
103 gfs2_statfs_change(sdp, ri.ri_data, ri.ri_data, 0);
105 buf += sizeof(struct gfs2_rindex);
113 gfs2_inplace_release(ip);
121 gfs2_glock_dq_uninit(&i_gh);
126 static void drop_dentries(struct gfs2_inode *ip)
131 inode = gfs2_ip2v_lookup(ip);
136 spin_lock(&dcache_lock);
137 list_for_each_entry(d, &inode->i_dentry, d_alias) {
142 spin_unlock(&dcache_lock);
146 spin_unlock(&dcache_lock);
151 /* This is called by an ioctl to rename an ordinary file that's represented
152 in the vfs to a hidden system file that isn't represented in the vfs. It's
153 used to add journals, along with the associated system files, to a fs. */
155 int gfs2_rename2system(struct gfs2_inode *ip,
156 struct gfs2_inode *old_dip, char *old_name,
157 struct gfs2_inode *new_dip, char *new_name)
159 struct gfs2_sbd *sdp = ip->i_sbd;
160 struct gfs2_holder ghs[3];
161 struct qstr old_qstr, new_qstr;
162 struct gfs2_inum inum;
164 struct buffer_head *dibh;
167 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, GL_NOCACHE, ghs);
168 gfs2_holder_init(old_dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
169 gfs2_holder_init(new_dip->i_gl, LM_ST_EXCLUSIVE, GL_SYNC, ghs + 2);
171 error = gfs2_glock_nq_m(3, ghs);
176 if (ip->i_di.di_nlink != 1)
179 if (!S_ISREG(ip->i_di.di_mode))
182 old_qstr.name = old_name;
183 old_qstr.len = strlen(old_name);
184 error = gfs2_dir_search(old_dip, &old_qstr, &inum, NULL);
193 if (!gfs2_inum_equal(&inum, &ip->i_num))
196 new_qstr.name = new_name;
197 new_qstr.len = strlen(new_name);
198 error = gfs2_dir_search(new_dip, &new_qstr, NULL, NULL);
210 error = gfs2_quota_hold(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
214 error = gfs2_diradd_alloc_required(new_dip, &new_qstr, &alloc_required);
218 if (alloc_required) {
219 struct gfs2_alloc *al = gfs2_alloc_get(new_dip);
221 al->al_requested = sdp->sd_max_dirres;
223 error = gfs2_inplace_reserve(new_dip);
227 error = gfs2_trans_begin(sdp,
229 al->al_rgd->rd_ri.ri_length +
230 3 * RES_DINODE + RES_LEAF +
231 RES_STATFS + RES_QUOTA, 0);
235 error = gfs2_trans_begin(sdp,
236 3 * RES_DINODE + 2 * RES_LEAF +
242 error = gfs2_dir_del(old_dip, &old_qstr);
246 error = gfs2_dir_add(new_dip, &new_qstr, &ip->i_num,
247 IF2DT(ip->i_di.di_mode));
251 gfs2_quota_change(ip, -ip->i_di.di_blocks, ip->i_di.di_uid,
254 error = gfs2_meta_inode_buffer(ip, &dibh);
257 ip->i_di.di_flags |= GFS2_DIF_SYSTEM;
258 gfs2_trans_add_bh(ip->i_gl, dibh);
259 gfs2_dinode_out(&ip->i_di, dibh->b_data);
269 gfs2_inplace_release(new_dip);
273 gfs2_alloc_put(new_dip);
276 gfs2_quota_unhold(ip);
282 gfs2_glock_dq_m(3, ghs);
285 gfs2_holder_uninit(ghs);
286 gfs2_holder_uninit(ghs + 1);
287 gfs2_holder_uninit(ghs + 2);