diff options
Diffstat (limited to 'fs/gfs2/rgrp.c')
-rw-r--r-- | fs/gfs2/rgrp.c | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c index 3cc402ce6fea..38fe18f2f055 100644 --- a/fs/gfs2/rgrp.c +++ b/fs/gfs2/rgrp.c | |||
@@ -553,7 +553,6 @@ void gfs2_free_clones(struct gfs2_rgrpd *rgd) | |||
553 | */ | 553 | */ |
554 | int gfs2_rs_alloc(struct gfs2_inode *ip) | 554 | int gfs2_rs_alloc(struct gfs2_inode *ip) |
555 | { | 555 | { |
556 | int error = 0; | ||
557 | struct gfs2_blkreserv *res; | 556 | struct gfs2_blkreserv *res; |
558 | 557 | ||
559 | if (ip->i_res) | 558 | if (ip->i_res) |
@@ -561,7 +560,7 @@ int gfs2_rs_alloc(struct gfs2_inode *ip) | |||
561 | 560 | ||
562 | res = kmem_cache_zalloc(gfs2_rsrv_cachep, GFP_NOFS); | 561 | res = kmem_cache_zalloc(gfs2_rsrv_cachep, GFP_NOFS); |
563 | if (!res) | 562 | if (!res) |
564 | error = -ENOMEM; | 563 | return -ENOMEM; |
565 | 564 | ||
566 | RB_CLEAR_NODE(&res->rs_node); | 565 | RB_CLEAR_NODE(&res->rs_node); |
567 | 566 | ||
@@ -571,7 +570,7 @@ int gfs2_rs_alloc(struct gfs2_inode *ip) | |||
571 | else | 570 | else |
572 | ip->i_res = res; | 571 | ip->i_res = res; |
573 | up_write(&ip->i_rw_mutex); | 572 | up_write(&ip->i_rw_mutex); |
574 | return error; | 573 | return 0; |
575 | } | 574 | } |
576 | 575 | ||
577 | static void dump_rs(struct seq_file *seq, const struct gfs2_blkreserv *rs) | 576 | static void dump_rs(struct seq_file *seq, const struct gfs2_blkreserv *rs) |
@@ -1263,7 +1262,9 @@ int gfs2_fitrim(struct file *filp, void __user *argp) | |||
1263 | int ret = 0; | 1262 | int ret = 0; |
1264 | u64 amt; | 1263 | u64 amt; |
1265 | u64 trimmed = 0; | 1264 | u64 trimmed = 0; |
1265 | u64 start, end, minlen; | ||
1266 | unsigned int x; | 1266 | unsigned int x; |
1267 | unsigned bs_shift = sdp->sd_sb.sb_bsize_shift; | ||
1267 | 1268 | ||
1268 | if (!capable(CAP_SYS_ADMIN)) | 1269 | if (!capable(CAP_SYS_ADMIN)) |
1269 | return -EPERM; | 1270 | return -EPERM; |
@@ -1271,19 +1272,25 @@ int gfs2_fitrim(struct file *filp, void __user *argp) | |||
1271 | if (!blk_queue_discard(q)) | 1272 | if (!blk_queue_discard(q)) |
1272 | return -EOPNOTSUPP; | 1273 | return -EOPNOTSUPP; |
1273 | 1274 | ||
1274 | if (argp == NULL) { | 1275 | if (copy_from_user(&r, argp, sizeof(r))) |
1275 | r.start = 0; | ||
1276 | r.len = ULLONG_MAX; | ||
1277 | r.minlen = 0; | ||
1278 | } else if (copy_from_user(&r, argp, sizeof(r))) | ||
1279 | return -EFAULT; | 1276 | return -EFAULT; |
1280 | 1277 | ||
1281 | ret = gfs2_rindex_update(sdp); | 1278 | ret = gfs2_rindex_update(sdp); |
1282 | if (ret) | 1279 | if (ret) |
1283 | return ret; | 1280 | return ret; |
1284 | 1281 | ||
1285 | rgd = gfs2_blk2rgrpd(sdp, r.start, 0); | 1282 | start = r.start >> bs_shift; |
1286 | rgd_end = gfs2_blk2rgrpd(sdp, r.start + r.len, 0); | 1283 | end = start + (r.len >> bs_shift); |
1284 | minlen = max_t(u64, r.minlen, | ||
1285 | q->limits.discard_granularity) >> bs_shift; | ||
1286 | |||
1287 | rgd = gfs2_blk2rgrpd(sdp, start, 0); | ||
1288 | rgd_end = gfs2_blk2rgrpd(sdp, end - 1, 0); | ||
1289 | |||
1290 | if (end <= start || | ||
1291 | minlen > sdp->sd_max_rg_data || | ||
1292 | start > rgd_end->rd_data0 + rgd_end->rd_data) | ||
1293 | return -EINVAL; | ||
1287 | 1294 | ||
1288 | while (1) { | 1295 | while (1) { |
1289 | 1296 | ||
@@ -1295,7 +1302,9 @@ int gfs2_fitrim(struct file *filp, void __user *argp) | |||
1295 | /* Trim each bitmap in the rgrp */ | 1302 | /* Trim each bitmap in the rgrp */ |
1296 | for (x = 0; x < rgd->rd_length; x++) { | 1303 | for (x = 0; x < rgd->rd_length; x++) { |
1297 | struct gfs2_bitmap *bi = rgd->rd_bits + x; | 1304 | struct gfs2_bitmap *bi = rgd->rd_bits + x; |
1298 | ret = gfs2_rgrp_send_discards(sdp, rgd->rd_data0, NULL, bi, r.minlen, &amt); | 1305 | ret = gfs2_rgrp_send_discards(sdp, |
1306 | rgd->rd_data0, NULL, bi, minlen, | ||
1307 | &amt); | ||
1299 | if (ret) { | 1308 | if (ret) { |
1300 | gfs2_glock_dq_uninit(&gh); | 1309 | gfs2_glock_dq_uninit(&gh); |
1301 | goto out; | 1310 | goto out; |
@@ -1324,7 +1333,7 @@ int gfs2_fitrim(struct file *filp, void __user *argp) | |||
1324 | 1333 | ||
1325 | out: | 1334 | out: |
1326 | r.len = trimmed << 9; | 1335 | r.len = trimmed << 9; |
1327 | if (argp && copy_to_user(argp, &r, sizeof(r))) | 1336 | if (copy_to_user(argp, &r, sizeof(r))) |
1328 | return -EFAULT; | 1337 | return -EFAULT; |
1329 | 1338 | ||
1330 | return ret; | 1339 | return ret; |