|
@@ -135,7 +135,9 @@ bool ceph_quota_is_same_realm(struct inode *old, struct inode *new)
|
|
|
|
|
|
enum quota_check_op {
|
|
enum quota_check_op {
|
|
QUOTA_CHECK_MAX_FILES_OP, /* check quota max_files limit */
|
|
QUOTA_CHECK_MAX_FILES_OP, /* check quota max_files limit */
|
|
- QUOTA_CHECK_MAX_BYTES_OP /* check quota max_files limit */
|
|
|
|
|
|
+ QUOTA_CHECK_MAX_BYTES_OP, /* check quota max_files limit */
|
|
|
|
+ QUOTA_CHECK_MAX_BYTES_APPROACHING_OP /* check if quota max_files
|
|
|
|
+ limit is approaching */
|
|
};
|
|
};
|
|
|
|
|
|
/*
|
|
/*
|
|
@@ -185,6 +187,20 @@ static bool check_quota_exceeded(struct inode *inode, enum quota_check_op op,
|
|
case QUOTA_CHECK_MAX_BYTES_OP:
|
|
case QUOTA_CHECK_MAX_BYTES_OP:
|
|
exceeded = (max && (rvalue + delta > max));
|
|
exceeded = (max && (rvalue + delta > max));
|
|
break;
|
|
break;
|
|
|
|
+ case QUOTA_CHECK_MAX_BYTES_APPROACHING_OP:
|
|
|
|
+ if (max) {
|
|
|
|
+ if (rvalue >= max)
|
|
|
|
+ exceeded = true;
|
|
|
|
+ else {
|
|
|
|
+ /*
|
|
|
|
+ * when we're writing more that 1/16th
|
|
|
|
+ * of the available space
|
|
|
|
+ */
|
|
|
|
+ exceeded =
|
|
|
|
+ (((max - rvalue) >> 4) < delta);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
default:
|
|
default:
|
|
/* Shouldn't happen */
|
|
/* Shouldn't happen */
|
|
pr_warn("Invalid quota check op (%d)\n", op);
|
|
pr_warn("Invalid quota check op (%d)\n", op);
|
|
@@ -238,3 +254,23 @@ bool ceph_quota_is_max_bytes_exceeded(struct inode *inode, loff_t newsize)
|
|
|
|
|
|
return check_quota_exceeded(inode, QUOTA_CHECK_MAX_BYTES_OP, (newsize - size));
|
|
return check_quota_exceeded(inode, QUOTA_CHECK_MAX_BYTES_OP, (newsize - size));
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+/*
|
|
|
|
+ * ceph_quota_is_max_bytes_approaching - check if we're reaching max_bytes
|
|
|
|
+ * @inode: inode being written
|
|
|
|
+ * @newsize: new size if write succeeds
|
|
|
|
+ *
|
|
|
|
+ * This function returns true if the new file size @newsize will be consuming
|
|
|
|
+ * more than 1/16th of the available quota space; it returns false otherwise.
|
|
|
|
+ */
|
|
|
|
+bool ceph_quota_is_max_bytes_approaching(struct inode *inode, loff_t newsize)
|
|
|
|
+{
|
|
|
|
+ loff_t size = ceph_inode(inode)->i_reported_size;
|
|
|
|
+
|
|
|
|
+ /* return immediately if we're decreasing file size */
|
|
|
|
+ if (newsize <= size)
|
|
|
|
+ return false;
|
|
|
|
+
|
|
|
|
+ return check_quota_exceeded(inode, QUOTA_CHECK_MAX_BYTES_APPROACHING_OP,
|
|
|
|
+ (newsize - size));
|
|
|
|
+}
|