Skip to content

Commit 12eb18f

Browse files
Thomas GrafPravin B Shelar
authored andcommitted
openvswitch: Constify various function arguments
Help produce better optimized code. Signed-off-by: Thomas Graf <[email protected]> Signed-off-by: Pravin B Shelar <[email protected]>
1 parent e8eedb8 commit 12eb18f

File tree

11 files changed

+38
-36
lines changed

11 files changed

+38
-36
lines changed

net/openvswitch/actions.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ static void action_fifo_init(struct action_fifo *fifo)
6969
fifo->tail = 0;
7070
}
7171

72-
static bool action_fifo_is_empty(struct action_fifo *fifo)
72+
static bool action_fifo_is_empty(const struct action_fifo *fifo)
7373
{
7474
return (fifo->head == fifo->tail);
7575
}
@@ -92,7 +92,7 @@ static struct deferred_action *action_fifo_put(struct action_fifo *fifo)
9292

9393
/* Return true if fifo is not full */
9494
static struct deferred_action *add_deferred_actions(struct sk_buff *skb,
95-
struct sw_flow_key *key,
95+
const struct sw_flow_key *key,
9696
const struct nlattr *attr)
9797
{
9898
struct action_fifo *fifo;
@@ -944,7 +944,8 @@ static void process_deferred_actions(struct datapath *dp)
944944

945945
/* Execute a list of actions against 'skb'. */
946946
int ovs_execute_actions(struct datapath *dp, struct sk_buff *skb,
947-
struct sw_flow_actions *acts, struct sw_flow_key *key)
947+
const struct sw_flow_actions *acts,
948+
struct sw_flow_key *key)
948949
{
949950
int level = this_cpu_read(exec_actions_level);
950951
int err;

net/openvswitch/datapath.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ const char *ovs_dp_name(const struct datapath *dp)
178178
return vport->ops->get_name(vport);
179179
}
180180

181-
static int get_dpifindex(struct datapath *dp)
181+
static int get_dpifindex(const struct datapath *dp)
182182
{
183183
struct vport *local;
184184
int ifindex;
@@ -633,7 +633,7 @@ static struct genl_family dp_packet_genl_family = {
633633
.n_ops = ARRAY_SIZE(dp_packet_genl_ops),
634634
};
635635

636-
static void get_dp_stats(struct datapath *dp, struct ovs_dp_stats *stats,
636+
static void get_dp_stats(const struct datapath *dp, struct ovs_dp_stats *stats,
637637
struct ovs_dp_megaflow_stats *mega_stats)
638638
{
639639
int i;
@@ -1352,7 +1352,7 @@ static struct sk_buff *ovs_dp_cmd_alloc_info(struct genl_info *info)
13521352

13531353
/* Called with rcu_read_lock or ovs_mutex. */
13541354
static struct datapath *lookup_datapath(struct net *net,
1355-
struct ovs_header *ovs_header,
1355+
const struct ovs_header *ovs_header,
13561356
struct nlattr *a[OVS_DP_ATTR_MAX + 1])
13571357
{
13581358
struct datapath *dp;
@@ -1380,7 +1380,7 @@ static void ovs_dp_reset_user_features(struct sk_buff *skb, struct genl_info *in
13801380
dp->user_features = 0;
13811381
}
13821382

1383-
static void ovs_dp_change(struct datapath *dp, struct nlattr **a)
1383+
static void ovs_dp_change(struct datapath *dp, struct nlattr *a[])
13841384
{
13851385
if (a[OVS_DP_ATTR_USER_FEATURES])
13861386
dp->user_features = nla_get_u32(a[OVS_DP_ATTR_USER_FEATURES]);
@@ -1744,7 +1744,7 @@ struct sk_buff *ovs_vport_cmd_build_info(struct vport *vport, u32 portid,
17441744

17451745
/* Called with ovs_mutex or RCU read lock. */
17461746
static struct vport *lookup_vport(struct net *net,
1747-
struct ovs_header *ovs_header,
1747+
const struct ovs_header *ovs_header,
17481748
struct nlattr *a[OVS_VPORT_ATTR_MAX + 1])
17491749
{
17501750
struct datapath *dp;

net/openvswitch/datapath.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ int lockdep_ovsl_is_held(void);
149149
#define rcu_dereference_ovsl(p) \
150150
rcu_dereference_check(p, lockdep_ovsl_is_held())
151151

152-
static inline struct net *ovs_dp_get_net(struct datapath *dp)
152+
static inline struct net *ovs_dp_get_net(const struct datapath *dp)
153153
{
154154
return read_pnet(&dp->net);
155155
}
@@ -192,7 +192,7 @@ struct sk_buff *ovs_vport_cmd_build_info(struct vport *, u32 pid, u32 seq,
192192
u8 cmd);
193193

194194
int ovs_execute_actions(struct datapath *dp, struct sk_buff *skb,
195-
struct sw_flow_actions *acts, struct sw_flow_key *);
195+
const struct sw_flow_actions *, struct sw_flow_key *);
196196

197197
void ovs_dp_notify_wq(struct work_struct *work);
198198

net/openvswitch/flow.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ u64 ovs_flow_used_time(unsigned long flow_jiffies)
6666
#define TCP_FLAGS_BE16(tp) (*(__be16 *)&tcp_flag_word(tp) & htons(0x0FFF))
6767

6868
void ovs_flow_stats_update(struct sw_flow *flow, __be16 tcp_flags,
69-
struct sk_buff *skb)
69+
const struct sk_buff *skb)
7070
{
7171
struct flow_stats *stats;
7272
int node = numa_node_id();
@@ -679,7 +679,7 @@ int ovs_flow_key_update(struct sk_buff *skb, struct sw_flow_key *key)
679679
return key_extract(skb, key);
680680
}
681681

682-
int ovs_flow_key_extract(struct ovs_tunnel_info *tun_info,
682+
int ovs_flow_key_extract(const struct ovs_tunnel_info *tun_info,
683683
struct sk_buff *skb, struct sw_flow_key *key)
684684
{
685685
/* Extract metadata from packet. */

net/openvswitch/flow.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ struct ovs_key_ipv4_tunnel {
5353

5454
struct ovs_tunnel_info {
5555
struct ovs_key_ipv4_tunnel tunnel;
56-
struct geneve_opt *options;
56+
const struct geneve_opt *options;
5757
u8 options_len;
5858
};
5959

@@ -73,7 +73,7 @@ static inline void __ovs_flow_tun_info_init(struct ovs_tunnel_info *tun_info,
7373
__be16 tp_dst,
7474
__be64 tun_id,
7575
__be16 tun_flags,
76-
struct geneve_opt *opts,
76+
const struct geneve_opt *opts,
7777
u8 opts_len)
7878
{
7979
tun_info->tunnel.tun_id = tun_id;
@@ -105,7 +105,7 @@ static inline void ovs_flow_tun_info_init(struct ovs_tunnel_info *tun_info,
105105
__be16 tp_dst,
106106
__be64 tun_id,
107107
__be16 tun_flags,
108-
struct geneve_opt *opts,
108+
const struct geneve_opt *opts,
109109
u8 opts_len)
110110
{
111111
__ovs_flow_tun_info_init(tun_info, iph->saddr, iph->daddr,
@@ -244,14 +244,15 @@ struct arp_eth_header {
244244
} __packed;
245245

246246
void ovs_flow_stats_update(struct sw_flow *, __be16 tcp_flags,
247-
struct sk_buff *);
247+
const struct sk_buff *);
248248
void ovs_flow_stats_get(const struct sw_flow *, struct ovs_flow_stats *,
249249
unsigned long *used, __be16 *tcp_flags);
250250
void ovs_flow_stats_clear(struct sw_flow *);
251251
u64 ovs_flow_used_time(unsigned long flow_jiffies);
252252

253253
int ovs_flow_key_update(struct sk_buff *skb, struct sw_flow_key *key);
254-
int ovs_flow_key_extract(struct ovs_tunnel_info *tun_info, struct sk_buff *skb,
254+
int ovs_flow_key_extract(const struct ovs_tunnel_info *tun_info,
255+
struct sk_buff *skb,
255256
struct sw_flow_key *key);
256257
/* Extract key from packet coming from userspace. */
257258
int ovs_flow_key_extract_userspace(const struct nlattr *attr,

net/openvswitch/flow_table.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ struct sw_flow *ovs_flow_alloc(void)
107107
return ERR_PTR(-ENOMEM);
108108
}
109109

110-
int ovs_flow_tbl_count(struct flow_table *table)
110+
int ovs_flow_tbl_count(const struct flow_table *table)
111111
{
112112
return table->count;
113113
}
@@ -401,7 +401,7 @@ static bool flow_cmp_masked_key(const struct sw_flow *flow,
401401
}
402402

403403
bool ovs_flow_cmp_unmasked_key(const struct sw_flow *flow,
404-
struct sw_flow_match *match)
404+
const struct sw_flow_match *match)
405405
{
406406
struct sw_flow_key *key = match->key;
407407
int key_start = flow_key_start(key);
@@ -412,7 +412,7 @@ bool ovs_flow_cmp_unmasked_key(const struct sw_flow *flow,
412412

413413
static struct sw_flow *masked_flow_lookup(struct table_instance *ti,
414414
const struct sw_flow_key *unmasked,
415-
struct sw_flow_mask *mask)
415+
const struct sw_flow_mask *mask)
416416
{
417417
struct sw_flow *flow;
418418
struct hlist_head *head;
@@ -460,7 +460,7 @@ struct sw_flow *ovs_flow_tbl_lookup(struct flow_table *tbl,
460460
}
461461

462462
struct sw_flow *ovs_flow_tbl_lookup_exact(struct flow_table *tbl,
463-
struct sw_flow_match *match)
463+
const struct sw_flow_match *match)
464464
{
465465
struct table_instance *ti = rcu_dereference_ovsl(tbl->ti);
466466
struct sw_flow_mask *mask;
@@ -563,7 +563,7 @@ static struct sw_flow_mask *flow_mask_find(const struct flow_table *tbl,
563563

564564
/* Add 'mask' into the mask list, if it is not already there. */
565565
static int flow_mask_insert(struct flow_table *tbl, struct sw_flow *flow,
566-
struct sw_flow_mask *new)
566+
const struct sw_flow_mask *new)
567567
{
568568
struct sw_flow_mask *mask;
569569
mask = flow_mask_find(tbl, new);
@@ -586,7 +586,7 @@ static int flow_mask_insert(struct flow_table *tbl, struct sw_flow *flow,
586586

587587
/* Must be called with OVS mutex held. */
588588
int ovs_flow_tbl_insert(struct flow_table *table, struct sw_flow *flow,
589-
struct sw_flow_mask *mask)
589+
const struct sw_flow_mask *mask)
590590
{
591591
struct table_instance *new_ti = NULL;
592592
struct table_instance *ti;

net/openvswitch/flow_table.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ struct sw_flow *ovs_flow_alloc(void);
6161
void ovs_flow_free(struct sw_flow *, bool deferred);
6262

6363
int ovs_flow_tbl_init(struct flow_table *);
64-
int ovs_flow_tbl_count(struct flow_table *table);
64+
int ovs_flow_tbl_count(const struct flow_table *table);
6565
void ovs_flow_tbl_destroy(struct flow_table *table);
6666
int ovs_flow_tbl_flush(struct flow_table *flow_table);
6767

6868
int ovs_flow_tbl_insert(struct flow_table *table, struct sw_flow *flow,
69-
struct sw_flow_mask *mask);
69+
const struct sw_flow_mask *mask);
7070
void ovs_flow_tbl_remove(struct flow_table *table, struct sw_flow *flow);
7171
int ovs_flow_tbl_num_masks(const struct flow_table *table);
7272
struct sw_flow *ovs_flow_tbl_dump_next(struct table_instance *table,
@@ -77,9 +77,9 @@ struct sw_flow *ovs_flow_tbl_lookup_stats(struct flow_table *,
7777
struct sw_flow *ovs_flow_tbl_lookup(struct flow_table *,
7878
const struct sw_flow_key *);
7979
struct sw_flow *ovs_flow_tbl_lookup_exact(struct flow_table *tbl,
80-
struct sw_flow_match *match);
80+
const struct sw_flow_match *match);
8181
bool ovs_flow_cmp_unmasked_key(const struct sw_flow *flow,
82-
struct sw_flow_match *match);
82+
const struct sw_flow_match *match);
8383

8484
void ovs_flow_mask_key(struct sw_flow_key *dst, const struct sw_flow_key *src,
8585
const struct sw_flow_mask *mask);

net/openvswitch/vport-geneve.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static void tunnel_id_to_vni(__be64 tun_id, __u8 *vni)
6868
}
6969

7070
/* Convert 24 bit VNI to 64 bit tunnel ID. */
71-
static __be64 vni_to_tunnel_id(__u8 *vni)
71+
static __be64 vni_to_tunnel_id(const __u8 *vni)
7272
{
7373
#ifdef __BIG_ENDIAN
7474
return (vni[0] << 16) | (vni[1] << 8) | vni[2];

net/openvswitch/vport-netdev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ static rx_handler_result_t netdev_frame_hook(struct sk_buff **pskb)
7777
return RX_HANDLER_CONSUMED;
7878
}
7979

80-
static struct net_device *get_dpdev(struct datapath *dp)
80+
static struct net_device *get_dpdev(const struct datapath *dp)
8181
{
8282
struct vport *local;
8383

net/openvswitch/vport.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void ovs_vport_exit(void)
6868
kfree(dev_table);
6969
}
7070

71-
static struct hlist_head *hash_bucket(struct net *net, const char *name)
71+
static struct hlist_head *hash_bucket(const struct net *net, const char *name)
7272
{
7373
unsigned int hash = jhash(name, strlen(name), (unsigned long) net);
7474
return &dev_table[hash & (VPORT_HASH_BUCKETS - 1)];
@@ -107,7 +107,7 @@ EXPORT_SYMBOL_GPL(ovs_vport_ops_unregister);
107107
*
108108
* Must be called with ovs or RCU read lock.
109109
*/
110-
struct vport *ovs_vport_locate(struct net *net, const char *name)
110+
struct vport *ovs_vport_locate(const struct net *net, const char *name)
111111
{
112112
struct hlist_head *bucket = hash_bucket(net, name);
113113
struct vport *vport;
@@ -380,7 +380,7 @@ int ovs_vport_get_options(const struct vport *vport, struct sk_buff *skb)
380380
*
381381
* Must be called with ovs_mutex.
382382
*/
383-
int ovs_vport_set_upcall_portids(struct vport *vport, struct nlattr *ids)
383+
int ovs_vport_set_upcall_portids(struct vport *vport, const struct nlattr *ids)
384384
{
385385
struct vport_portids *old, *vport_portids;
386386

@@ -471,7 +471,7 @@ u32 ovs_vport_find_upcall_portid(const struct vport *vport, struct sk_buff *skb)
471471
* skb->data should point to the Ethernet header.
472472
*/
473473
void ovs_vport_receive(struct vport *vport, struct sk_buff *skb,
474-
struct ovs_tunnel_info *tun_info)
474+
const struct ovs_tunnel_info *tun_info)
475475
{
476476
struct pcpu_sw_netstats *stats;
477477
struct sw_flow_key key;

0 commit comments

Comments
 (0)