Re: [Cluster-devel] [GFS2 PATCH 3/4] gfs2: add new function gfs2_inpl_rsrv_ret_max_avl

2015-02-13 Thread Steven Whitehouse

Hi,

Likewise here, if the available blocks was added to the allocation 
parms, then this would help to neaten up the code a bit. Otherwise all 
four patches look good to me,


Steve.

On 12/02/15 16:54, Abhi Das wrote:

This is a variant of the existing gfs2_inplace_reserve() function.

If the requested number of blocks are not available to be reserved
from any of the rgrps, gfs2_inplace_reserve() return -ENOSPC.
gfs2_inpl_rsrv_ret_max_val() will also return the maximum blocks
available in an extra parameter 'max_avail'.

If acceptable to the caller logic, either of these inplace resreve
functions may be called again requesting 'max_avail' blocks to
avoid the -ENOSPC error.

Signed-off-by: Abhi Das a...@redhat.com
---
  fs/gfs2/rgrp.c | 13 +++--
  fs/gfs2/rgrp.h | 10 +-
  2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
index 9150207..0fa9ae3 100644
--- a/fs/gfs2/rgrp.c
+++ b/fs/gfs2/rgrp.c
@@ -1942,14 +1942,17 @@ static inline int fast_to_acquire(struct gfs2_rgrpd 
*rgd)
  }
  
  /**

- * gfs2_inplace_reserve - Reserve space in the filesystem
+ * gfs2_inpl_rsrv_ret_max_avl - Reserve space in the filesystem
   * @ip: the inode to reserve space for
   * @ap: the allocation parameters
+ * @max_avail: If non-NULL, return the max available extent if -ENOSPC
   *
   * Returns: errno
   */
  
-int gfs2_inplace_reserve(struct gfs2_inode *ip, const struct gfs2_alloc_parms *ap)

+int gfs2_inpl_rsrv_ret_max_avl(struct gfs2_inode *ip,
+  const struct gfs2_alloc_parms *ap,
+  u32 *max_avail)
  {
struct gfs2_sbd *sdp = GFS2_SB(ip-i_inode);
struct gfs2_rgrpd *begin = NULL;
@@ -1958,6 +1961,7 @@ int gfs2_inplace_reserve(struct gfs2_inode *ip, const 
struct gfs2_alloc_parms *a
u64 last_unlinked = NO_BLOCK;
int loops = 0;
u32 skip = 0;
+   u32 max_avlbl = 0;
  
  	if (sdp-sd_args.ar_rgrplvb)

flags |= GL_SKIP;
@@ -2030,6 +2034,8 @@ int gfs2_inplace_reserve(struct gfs2_inode *ip, const 
struct gfs2_alloc_parms *a
if (rs-rs_rbm.rgd-rd_free_clone = ap-target) {
ip-i_rgd = rs-rs_rbm.rgd;
return 0;
+   } else if (rs-rs_rbm.rgd-rd_free_clone  max_avlbl) {
+   max_avlbl = rs-rs_rbm.rgd-rd_free_clone;
}
  
  check_rgrp:

@@ -2068,6 +2074,9 @@ next_rgrp:
gfs2_log_flush(sdp, NULL, NORMAL_FLUSH);
}
  
+	if (max_avail)

+   *max_avail = max_avlbl;
+
return -ENOSPC;
  }
  
diff --git a/fs/gfs2/rgrp.h b/fs/gfs2/rgrp.h

index b104f4a..2adffca 100644
--- a/fs/gfs2/rgrp.h
+++ b/fs/gfs2/rgrp.h
@@ -41,7 +41,15 @@ extern void gfs2_rgrp_go_unlock(struct gfs2_holder *gh);
  extern struct gfs2_alloc *gfs2_alloc_get(struct gfs2_inode *ip);
  
  #define GFS2_AF_ORLOV 1

-extern int gfs2_inplace_reserve(struct gfs2_inode *ip, const struct 
gfs2_alloc_parms *ap);
+extern int gfs2_inpl_rsrv_ret_max_avl(struct gfs2_inode *ip,
+ const struct gfs2_alloc_parms *ap,
+ u32 *max_avail);
+static inline int gfs2_inplace_reserve(struct gfs2_inode *ip,
+  const struct gfs2_alloc_parms *ap)
+{
+   return gfs2_inpl_rsrv_ret_max_avl(ip, ap, NULL);
+}
+
  extern void gfs2_inplace_release(struct gfs2_inode *ip);
  
  extern int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *n,




[Cluster-devel] [GFS2 PATCH 3/4] gfs2: add new function gfs2_inpl_rsrv_ret_max_avl

2015-02-12 Thread Abhi Das
This is a variant of the existing gfs2_inplace_reserve() function.

If the requested number of blocks are not available to be reserved
from any of the rgrps, gfs2_inplace_reserve() return -ENOSPC.
gfs2_inpl_rsrv_ret_max_val() will also return the maximum blocks
available in an extra parameter 'max_avail'.

If acceptable to the caller logic, either of these inplace resreve
functions may be called again requesting 'max_avail' blocks to
avoid the -ENOSPC error.

Signed-off-by: Abhi Das a...@redhat.com
---
 fs/gfs2/rgrp.c | 13 +++--
 fs/gfs2/rgrp.h | 10 +-
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
index 9150207..0fa9ae3 100644
--- a/fs/gfs2/rgrp.c
+++ b/fs/gfs2/rgrp.c
@@ -1942,14 +1942,17 @@ static inline int fast_to_acquire(struct gfs2_rgrpd 
*rgd)
 }
 
 /**
- * gfs2_inplace_reserve - Reserve space in the filesystem
+ * gfs2_inpl_rsrv_ret_max_avl - Reserve space in the filesystem
  * @ip: the inode to reserve space for
  * @ap: the allocation parameters
+ * @max_avail: If non-NULL, return the max available extent if -ENOSPC
  *
  * Returns: errno
  */
 
-int gfs2_inplace_reserve(struct gfs2_inode *ip, const struct gfs2_alloc_parms 
*ap)
+int gfs2_inpl_rsrv_ret_max_avl(struct gfs2_inode *ip,
+  const struct gfs2_alloc_parms *ap,
+  u32 *max_avail)
 {
struct gfs2_sbd *sdp = GFS2_SB(ip-i_inode);
struct gfs2_rgrpd *begin = NULL;
@@ -1958,6 +1961,7 @@ int gfs2_inplace_reserve(struct gfs2_inode *ip, const 
struct gfs2_alloc_parms *a
u64 last_unlinked = NO_BLOCK;
int loops = 0;
u32 skip = 0;
+   u32 max_avlbl = 0;
 
if (sdp-sd_args.ar_rgrplvb)
flags |= GL_SKIP;
@@ -2030,6 +2034,8 @@ int gfs2_inplace_reserve(struct gfs2_inode *ip, const 
struct gfs2_alloc_parms *a
if (rs-rs_rbm.rgd-rd_free_clone = ap-target) {
ip-i_rgd = rs-rs_rbm.rgd;
return 0;
+   } else if (rs-rs_rbm.rgd-rd_free_clone  max_avlbl) {
+   max_avlbl = rs-rs_rbm.rgd-rd_free_clone;
}
 
 check_rgrp:
@@ -2068,6 +2074,9 @@ next_rgrp:
gfs2_log_flush(sdp, NULL, NORMAL_FLUSH);
}
 
+   if (max_avail)
+   *max_avail = max_avlbl;
+
return -ENOSPC;
 }
 
diff --git a/fs/gfs2/rgrp.h b/fs/gfs2/rgrp.h
index b104f4a..2adffca 100644
--- a/fs/gfs2/rgrp.h
+++ b/fs/gfs2/rgrp.h
@@ -41,7 +41,15 @@ extern void gfs2_rgrp_go_unlock(struct gfs2_holder *gh);
 extern struct gfs2_alloc *gfs2_alloc_get(struct gfs2_inode *ip);
 
 #define GFS2_AF_ORLOV 1
-extern int gfs2_inplace_reserve(struct gfs2_inode *ip, const struct 
gfs2_alloc_parms *ap);
+extern int gfs2_inpl_rsrv_ret_max_avl(struct gfs2_inode *ip,
+ const struct gfs2_alloc_parms *ap,
+ u32 *max_avail);
+static inline int gfs2_inplace_reserve(struct gfs2_inode *ip,
+  const struct gfs2_alloc_parms *ap)
+{
+   return gfs2_inpl_rsrv_ret_max_avl(ip, ap, NULL);
+}
+
 extern void gfs2_inplace_release(struct gfs2_inode *ip);
 
 extern int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *n,
-- 
1.8.1.4