From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alex Vesker Subject: [PATCH net-next v2 02/11] devlink: Add callback to query for snapshot id before snapshot create Date: Wed, 11 Jul 2018 13:42:59 +0300 Message-ID: <1531305788-29420-3-git-send-email-valex@mellanox.com> References: <1531305788-29420-1-git-send-email-valex@mellanox.com> Cc: dsahern@gmail.com, andrew@lunn.ch, rahul.lakkireddy@chelsio.com, Alex Vesker To: netdev@vger.kernel.org, jiri@mellanox.com Return-path: Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:53005 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732287AbeGKKr1 (ORCPT ); Wed, 11 Jul 2018 06:47:27 -0400 In-Reply-To: <1531305788-29420-1-git-send-email-valex@mellanox.com> Sender: netdev-owner@vger.kernel.org List-ID: To restrict the driver with the snapshot ID selection a new callback is introduced for the driver to get the snapshot ID before creating a new snapshot. This will also allow giving the same ID for multiple snapshots taken of different regions on the same time. Signed-off-by: Alex Vesker Signed-off-by: Jiri Pirko --- include/net/devlink.h | 8 ++++++++ net/core/devlink.c | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/include/net/devlink.h b/include/net/devlink.h index e539765..f27d859 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -29,6 +29,7 @@ struct devlink { struct list_head resource_list; struct list_head param_list; struct list_head region_list; + u32 snapshot_id; struct devlink_dpipe_headers *dpipe_headers; const struct devlink_ops *ops; struct device *dev; @@ -551,6 +552,7 @@ struct devlink_region *devlink_region_create(struct devlink *devlink, u32 region_max_snapshots, u64 region_size); void devlink_region_destroy(struct devlink_region *region); +u32 devlink_region_shapshot_id_get(struct devlink *devlink); #else @@ -792,6 +794,12 @@ static inline bool devlink_dpipe_table_counter_enabled(struct devlink *devlink, { } +static inline u32 +devlink_region_shapshot_id_get(struct devlink *devlink) +{ + return 0; +} + #endif #endif /* _NET_DEVLINK_H_ */ diff --git a/net/core/devlink.c b/net/core/devlink.c index cac8561..6c92ddd 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -4193,6 +4193,27 @@ void devlink_region_destroy(struct devlink_region *region) } EXPORT_SYMBOL_GPL(devlink_region_destroy); +/** + * devlink_region_shapshot_id_get - get snapshot ID + * + * This callback should be called when adding a new snapshot, + * Driver should use the same id for multiple snapshots taken + * on multiple regions at the same time/by the same trigger. + * + * @devlink: devlink + */ +u32 devlink_region_shapshot_id_get(struct devlink *devlink) +{ + u32 id; + + mutex_lock(&devlink->lock); + id = ++devlink->snapshot_id; + mutex_unlock(&devlink->lock); + + return id; +} +EXPORT_SYMBOL_GPL(devlink_region_shapshot_id_get); + static int __init devlink_module_init(void) { return genl_register_family(&devlink_nl_family); -- 1.8.3.1