Skip to contentSkip to conversation

vhost: scsi: constify target_core_fabric_ops structures

PATCH In review Bhumika Goyal 3 participants 6 messages Jan 9, 2017 – Jan 10, 2017

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vhost: scsi: constify target_core_fabric_ops structures

Declare target_core_fabric_ops strucrues as const as they are only passed as an argument to the functions target_register_template and target_unregister_template. The arguments are of type const struct target_core_fabric_ops *, so target_core_fabric_ops structures having this property can be declared const.
Done using Coccinelle:

@r disable optional_qualifier@
identifier i;
position p;
@@
static struct target_core_fabric_ops i@p={...};

@ok@
position p;
identifier r.i;
@@
(
target_register_template(&i@p)
|
target_unregister_template(&i@p)
)
@bad@
position p!={r.p,ok.p};
identifier r.i;
@@
i@p

@depends on !bad disable optional_qualifier@
identifier r.i;
@@
+const
struct target_core_fabric_ops i;

File size before: drivers/vhost/scsi.o
text data bss dec hex filename
18063 2985 40 21088 5260 drivers/vhost/scsi.o

File size after: drivers/vhost/scsi.o
text data bss dec hex filename
18479 2601 40 21120 5280 drivers/vhost/scsi.o

---
 drivers/vhost/scsi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vhost/scsi.c +1 -1
index 253310c..620366d 100644
@@ -2087,7 +2087,7 @@ static void vhost_scsi_drop_tport(struct se_wwn *wwn)
 	NULL,
 };
 
-static struct target_core_fabric_ops vhost_scsi_ops = {
+static const struct target_core_fabric_ops vhost_scsi_ops = {
 	.module				= THIS_MODULE,
 	.name				= "vhost",
 	.get_fabric_name		= vhost_scsi_get_fabric_name,
Signature · 1 line
1.9.1
Acked-by on v1 1/1
#1 lore raw
Quoted 52 lines · Bhumika Goyal

Declare target_core_fabric_ops strucrues as const as they are only passed as an argument to the functions target_register_template and target_unregister_template. The arguments are of type const struct target_core_fabric_ops *, so target_core_fabric_ops structures having this property can be declared const.
Done using Coccinelle:

@r disable optional_qualifier@
identifier i;
position p;
@@
static struct target_core_fabric_ops i@p={...};

@ok@
position p;
identifier r.i;
@@
(
target_register_template(&i@p)
|
target_unregister_template(&i@p)
)
@bad@
position p!={r.p,ok.p};
identifier r.i;
@@
i@p

@depends on !bad disable optional_qualifier@
identifier r.i;
@@
+const
struct target_core_fabric_ops i;

File size before: drivers/vhost/scsi.o
text data bss dec hex filename
18063 2985 40 21088 5260 drivers/vhost/scsi.o

File size after: drivers/vhost/scsi.o
text data bss dec hex filename
18479 2601 40 21120 5280 drivers/vhost/scsi.o

---
  drivers/vhost/scsi.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vhost/scsi.c +0 -0
index 253310c..620366d 100644

drivers/vhost/scsi.c static void vhost_scsi_drop_tport(struct se_wwn *wwn) · line 2093

Quoted 8 lines
drivers/vhost/scsi.c +1 -1
@@ -2087,7 +2087,7 @@ static void vhost_scsi_drop_tport(struct se_wwn *wwn)
  	NULL,
  };
 
-static struct target_core_fabric_ops vhost_scsi_ops = {
+static const struct target_core_fabric_ops vhost_scsi_ops = {
  	.module				= THIS_MODULE,
  	.name				= "vhost",
  	.get_fabric_name		= vhost_scsi_get_fabric_name,

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#2 lore raw
In reply to Bhumika Goyal
Quoted 34 lines · Bhumika Goyal

Declare target_core_fabric_ops strucrues as const as they are only passed as an argument to the functions target_register_template and target_unregister_template. The arguments are of type const struct target_core_fabric_ops *, so target_core_fabric_ops structures having this property can be declared const.
Done using Coccinelle:

@r disable optional_qualifier@
identifier i;
position p;
@@
static struct target_core_fabric_ops i@p={...};

@ok@
position p;
identifier r.i;
@@
(
target_register_template(&i@p)
|
target_unregister_template(&i@p)
)
@bad@
position p!={r.p,ok.p};
identifier r.i;
@@
i@p

@depends on !bad disable optional_qualifier@
identifier r.i;
@@
+const
struct target_core_fabric_ops i;

Quoted 7 lines

File size before: drivers/vhost/scsi.o
text data bss dec hex filename
18063 2985 40 21088 5260 drivers/vhost/scsi.o

File size after: drivers/vhost/scsi.o
text data bss dec hex filename
18479 2601 40 21120 5280 drivers/vhost/scsi.o

What are these numbers trying to prove?

Quoted 10 lines
---
 drivers/vhost/scsi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vhost/scsi.c +0 -0
index 253310c..620366d 100644

drivers/vhost/scsi.c static void vhost_scsi_drop_tport(struct se_wwn *wwn) · line 2093

Quoted 8 lines
drivers/vhost/scsi.c +1 -1
@@ -2087,7 +2087,7 @@ static void vhost_scsi_drop_tport(struct se_wwn *wwn)
 	NULL,
 };
 
-static struct target_core_fabric_ops vhost_scsi_ops = {
+static const struct target_core_fabric_ops vhost_scsi_ops = {
 	.module				= THIS_MODULE,
 	.name				= "vhost",
 	.get_fabric_name		= vhost_scsi_get_fabric_name,

If it can be const it probably should ...

Quoted 2 lines
Signature · 1 line
1.9.1
#3 lore raw
Quoted 39 lines · Michael S. Tsirkin
Quoted 38 lines · Bhumika Goyal

Declare target_core_fabric_ops strucrues as const as they are only passed as an argument to the functions target_register_template and target_unregister_template. The arguments are of type const struct target_core_fabric_ops *, so target_core_fabric_ops structures having this property can be declared const.
Done using Coccinelle:

@r disable optional_qualifier@
identifier i;
position p;
@@
static struct target_core_fabric_ops i@p={...};

@ok@
position p;
identifier r.i;
@@
(
target_register_template(&i@p)
|
target_unregister_template(&i@p)
)
@bad@
position p!={r.p,ok.p};
identifier r.i;
@@
i@p

@depends on !bad disable optional_qualifier@
identifier r.i;
@@
+const
struct target_core_fabric_ops i;

File size before: drivers/vhost/scsi.o
text data bss dec hex filename
18063 2985 40 21088 5260 drivers/vhost/scsi.o

Quoted 6 lines
Quoted 3 lines

File size after: drivers/vhost/scsi.o
text data bss dec hex filename
18479 2601 40 21120 5280 drivers/vhost/scsi.o

What are these numbers trying to prove?

These numbers show that adding const has decreased the size of the data segment and increased the size of the text segment, suggesting that the changed code has been compiled and the const annotation has had an effect.

Thanks,
Bhumika

Quoted 24 lines
Quoted 11 lines
---
 drivers/vhost/scsi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vhost/scsi.c +0 -0
index 253310c..620366d 100644

drivers/vhost/scsi.c static void vhost_scsi_drop_tport(struct se_wwn *wwn) · line 2093

Quoted 8 lines
drivers/vhost/scsi.c +1 -1
@@ -2087,7 +2087,7 @@ static void vhost_scsi_drop_tport(struct se_wwn *wwn)
      NULL,
 };
 
-static struct target_core_fabric_ops vhost_scsi_ops = {
+static const struct target_core_fabric_ops vhost_scsi_ops = {
      .module                         = THIS_MODULE,
      .name                           = "vhost",
      .get_fabric_name                = vhost_scsi_get_fabric_name,

If it can be const it probably should ...

Quoted 2 lines

--
1.9.1

#4 lore raw
Quoted 47 lines · Bhumika Goyal
Quoted 39 lines · Michael S. Tsirkin
Quoted 38 lines · Bhumika Goyal

Declare target_core_fabric_ops strucrues as const as they are only passed as an argument to the functions target_register_template and target_unregister_template. The arguments are of type const struct target_core_fabric_ops *, so target_core_fabric_ops structures having this property can be declared const.
Done using Coccinelle:

@r disable optional_qualifier@
identifier i;
position p;
@@
static struct target_core_fabric_ops i@p={...};

@ok@
position p;
identifier r.i;
@@
(
target_register_template(&i@p)
|
target_unregister_template(&i@p)
)
@bad@
position p!={r.p,ok.p};
identifier r.i;
@@
i@p

@depends on !bad disable optional_qualifier@
identifier r.i;
@@
+const
struct target_core_fabric_ops i;

File size before: drivers/vhost/scsi.o
text data bss dec hex filename
18063 2985 40 21088 5260 drivers/vhost/scsi.o

Quoted 6 lines
Quoted 3 lines

File size after: drivers/vhost/scsi.o
text data bss dec hex filename
18479 2601 40 21120 5280 drivers/vhost/scsi.o

What are these numbers trying to prove?

Quoted 7 lines

These numbers show that adding const has decreased the size of the data segment and increased the size of the text segment, suggesting that the changed code has been compiled and the const annotation has had an effect.

Thanks,
Bhumika

I wonder why there's a net increase in memory consumption though.

Quoted 24 lines
Quoted 24 lines
Quoted 11 lines
---
 drivers/vhost/scsi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vhost/scsi.c +0 -0
index 253310c..620366d 100644

drivers/vhost/scsi.c static void vhost_scsi_drop_tport(struct se_wwn *wwn) · line 2093

Quoted 8 lines
drivers/vhost/scsi.c +1 -1
@@ -2087,7 +2087,7 @@ static void vhost_scsi_drop_tport(struct se_wwn *wwn)
      NULL,
 };
 
-static struct target_core_fabric_ops vhost_scsi_ops = {
+static const struct target_core_fabric_ops vhost_scsi_ops = {
      .module                         = THIS_MODULE,
      .name                           = "vhost",
      .get_fabric_name                = vhost_scsi_get_fabric_name,

If it can be const it probably should ...

Quoted 2 lines

--
1.9.1

#5 lore raw
In reply to Michael S. Tsirkin
Quoted 39 lines · Michael S. Tsirkin
Quoted 38 lines · Bhumika Goyal

Declare target_core_fabric_ops strucrues as const as they are only passed as an argument to the functions target_register_template and target_unregister_template. The arguments are of type const struct target_core_fabric_ops *, so target_core_fabric_ops structures having this property can be declared const.
Done using Coccinelle:

@r disable optional_qualifier@
identifier i;
position p;
@@
static struct target_core_fabric_ops i@p={...};

@ok@
position p;
identifier r.i;
@@
(
target_register_template(&i@p)
|
target_unregister_template(&i@p)
)
@bad@
position p!={r.p,ok.p};
identifier r.i;
@@
i@p

@depends on !bad disable optional_qualifier@
identifier r.i;
@@
+const
struct target_core_fabric_ops i;

File size before: drivers/vhost/scsi.o
text data bss dec hex filename
18063 2985 40 21088 5260 drivers/vhost/scsi.o

Quoted 6 lines
Quoted 3 lines

File size after: drivers/vhost/scsi.o
text data bss dec hex filename
18479 2601 40 21120 5280 drivers/vhost/scsi.o

What are these numbers trying to prove?

These numbers show that adding const has decreased the size of the data segment and increased the size of the text segment, suggesting that the changed code has been compiled and the const annotation has had an effect.

Thanks,
Bhumika

Quoted 24 lines
Quoted 11 lines
---
 drivers/vhost/scsi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vhost/scsi.c +0 -0
index 253310c..620366d 100644

drivers/vhost/scsi.c static void vhost_scsi_drop_tport(struct se_wwn *wwn) · line 2093

Quoted 8 lines
drivers/vhost/scsi.c +1 -1
@@ -2087,7 +2087,7 @@ static void vhost_scsi_drop_tport(struct se_wwn *wwn)
      NULL,
 };
 
-static struct target_core_fabric_ops vhost_scsi_ops = {
+static const struct target_core_fabric_ops vhost_scsi_ops = {
      .module                         = THIS_MODULE,
      .name                           = "vhost",
      .get_fabric_name                = vhost_scsi_get_fabric_name,

If it can be const it probably should ...

Quoted 2 lines

--
1.9.1