Skip to content

Commit aa711ee

Browse files
Alex ElderSage Weil
authored andcommitted
ceph: define snap counts as u32 everywhere
There are two structures in which a count of snapshots are maintained: struct ceph_snap_context { ... u32 num_snaps; ... } and struct ceph_snap_realm { ... u32 num_prior_parent_snaps; /* had prior to parent_since */ ... u32 num_snaps; ... } These fields never take on negative values (e.g., to hold special meaning), and so are really inherently unsigned. Furthermore they take their value from over-the-wire or on-disk formatted 32-bit values. So change their definition to have type u32, and change some spots elsewhere in the code to account for this change. Signed-off-by: Alex Elder <elder@inktank.com> Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
1 parent bd919d4 commit aa711ee

3 files changed

Lines changed: 13 additions & 11 deletions

File tree

‎fs/ceph/snap.c‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,7 @@ static int build_snap_context(struct ceph_snap_realm *realm)
296296
struct ceph_snap_realm *parent = realm->parent;
297297
struct ceph_snap_context *snapc;
298298
int err = 0;
299-
int i;
300-
int num = realm->num_prior_parent_snaps + realm->num_snaps;
299+
u32 num = realm->num_prior_parent_snaps + realm->num_snaps;
301300

302301
/*
303302
* build parent context, if it hasn't been built.
@@ -321,11 +320,11 @@ static int build_snap_context(struct ceph_snap_realm *realm)
321320
realm->cached_context->seq == realm->seq &&
322321
(!parent ||
323322
realm->cached_context->seq >= parent->cached_context->seq)) {
324-
dout("build_snap_context %llx %p: %p seq %lld (%d snaps)"
323+
dout("build_snap_context %llx %p: %p seq %lld (%u snaps)"
325324
" (unchanged)\n",
326325
realm->ino, realm, realm->cached_context,
327326
realm->cached_context->seq,
328-
realm->cached_context->num_snaps);
327+
(unsigned int) realm->cached_context->num_snaps);
329328
return 0;
330329
}
331330

@@ -342,6 +341,8 @@ static int build_snap_context(struct ceph_snap_realm *realm)
342341
num = 0;
343342
snapc->seq = realm->seq;
344343
if (parent) {
344+
u32 i;
345+
345346
/* include any of parent's snaps occurring _after_ my
346347
parent became my parent */
347348
for (i = 0; i < parent->cached_context->num_snaps; i++)
@@ -361,8 +362,9 @@ static int build_snap_context(struct ceph_snap_realm *realm)
361362

362363
sort(snapc->snaps, num, sizeof(u64), cmpu64_rev, NULL);
363364
snapc->num_snaps = num;
364-
dout("build_snap_context %llx %p: %p seq %lld (%d snaps)\n",
365-
realm->ino, realm, snapc, snapc->seq, snapc->num_snaps);
365+
dout("build_snap_context %llx %p: %p seq %lld (%u snaps)\n",
366+
realm->ino, realm, snapc, snapc->seq,
367+
(unsigned int) snapc->num_snaps);
366368

367369
if (realm->cached_context)
368370
ceph_put_snap_context(realm->cached_context);
@@ -402,9 +404,9 @@ static void rebuild_snap_realms(struct ceph_snap_realm *realm)
402404
* helper to allocate and decode an array of snapids. free prior
403405
* instance, if any.
404406
*/
405-
static int dup_array(u64 **dst, __le64 *src, int num)
407+
static int dup_array(u64 **dst, __le64 *src, u32 num)
406408
{
407-
int i;
409+
u32 i;
408410

409411
kfree(*dst);
410412
if (num) {

‎fs/ceph/super.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,9 +612,9 @@ struct ceph_snap_realm {
612612
u64 parent_since; /* snapid when our current parent became so */
613613

614614
u64 *prior_parent_snaps; /* snaps inherited from any parents we */
615-
int num_prior_parent_snaps; /* had prior to parent_since */
615+
u32 num_prior_parent_snaps; /* had prior to parent_since */
616616
u64 *snaps; /* snaps specific to this realm */
617-
int num_snaps;
617+
u32 num_snaps;
618618

619619
struct ceph_snap_realm *parent;
620620
struct list_head children; /* list of child realms */

‎include/linux/ceph/libceph.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ struct ceph_client {
154154
struct ceph_snap_context {
155155
atomic_t nref;
156156
u64 seq;
157-
int num_snaps;
157+
u32 num_snaps;
158158
u64 snaps[];
159159
};
160160

0 commit comments

Comments
 (0)