Skip to content

Commit a006d46

Browse files
alexveskerdavem330
authored andcommitted
devlink: Extend the support querying for region snapshot IDs
Extend the support for DEVLINK_CMD_REGION_GET command to also return the IDs of the snapshot currently present on the region. Each reply will include a nested snapshots attribute that can contain multiple snapshot attributes each with an ID. Signed-off-by: Alex Vesker <[email protected]> Signed-off-by: Jiri Pirko <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent d8db7ea commit a006d46

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

include/uapi/linux/devlink.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@ enum devlink_attr {
267267

268268
DEVLINK_ATTR_REGION_NAME, /* string */
269269
DEVLINK_ATTR_REGION_SIZE, /* u64 */
270+
DEVLINK_ATTR_REGION_SNAPSHOTS, /* nested */
271+
DEVLINK_ATTR_REGION_SNAPSHOT, /* nested */
272+
DEVLINK_ATTR_REGION_SNAPSHOT_ID, /* u32 */
270273

271274
/* add new attributes above here, update the policy in devlink.c */
272275

net/core/devlink.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3149,6 +3149,55 @@ static void devlink_param_unregister_one(struct devlink *devlink,
31493149
kfree(param_item);
31503150
}
31513151

3152+
static int devlink_nl_region_snapshot_id_put(struct sk_buff *msg,
3153+
struct devlink *devlink,
3154+
struct devlink_snapshot *snapshot)
3155+
{
3156+
struct nlattr *snap_attr;
3157+
int err;
3158+
3159+
snap_attr = nla_nest_start(msg, DEVLINK_ATTR_REGION_SNAPSHOT);
3160+
if (!snap_attr)
3161+
return -EINVAL;
3162+
3163+
err = nla_put_u32(msg, DEVLINK_ATTR_REGION_SNAPSHOT_ID, snapshot->id);
3164+
if (err)
3165+
goto nla_put_failure;
3166+
3167+
nla_nest_end(msg, snap_attr);
3168+
return 0;
3169+
3170+
nla_put_failure:
3171+
nla_nest_cancel(msg, snap_attr);
3172+
return err;
3173+
}
3174+
3175+
static int devlink_nl_region_snapshots_id_put(struct sk_buff *msg,
3176+
struct devlink *devlink,
3177+
struct devlink_region *region)
3178+
{
3179+
struct devlink_snapshot *snapshot;
3180+
struct nlattr *snapshots_attr;
3181+
int err;
3182+
3183+
snapshots_attr = nla_nest_start(msg, DEVLINK_ATTR_REGION_SNAPSHOTS);
3184+
if (!snapshots_attr)
3185+
return -EINVAL;
3186+
3187+
list_for_each_entry(snapshot, &region->snapshot_list, list) {
3188+
err = devlink_nl_region_snapshot_id_put(msg, devlink, snapshot);
3189+
if (err)
3190+
goto nla_put_failure;
3191+
}
3192+
3193+
nla_nest_end(msg, snapshots_attr);
3194+
return 0;
3195+
3196+
nla_put_failure:
3197+
nla_nest_cancel(msg, snapshots_attr);
3198+
return err;
3199+
}
3200+
31523201
static int devlink_nl_region_fill(struct sk_buff *msg, struct devlink *devlink,
31533202
enum devlink_command cmd, u32 portid,
31543203
u32 seq, int flags,
@@ -3175,6 +3224,10 @@ static int devlink_nl_region_fill(struct sk_buff *msg, struct devlink *devlink,
31753224
if (err)
31763225
goto nla_put_failure;
31773226

3227+
err = devlink_nl_region_snapshots_id_put(msg, devlink, region);
3228+
if (err)
3229+
goto nla_put_failure;
3230+
31783231
genlmsg_end(msg, hdr);
31793232
return 0;
31803233

0 commit comments

Comments
 (0)