Skip to contentSkip to conversation

mtd: cmdlinepart: fix the wrong partitions number when truncating occurs

PATCH In review Huang Shijie 4 participants 12 messages Aug 25, 2012 – Aug 29, 2012 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 mtd: cmdlinepart: fix the wrong partitions number when truncating occurs

Assume we have a 1GB(8Gb) nand chip, and we set the partitions in the command line like this:

    #gpmi-nand:100m(boot),100m(kernel),1g(rootfs)

In this case, the partition truncating occurs. The current code will get the following result:

     ----------------------------------
	root@freescale ~$ cat /proc/mtd
	dev:    size   erasesize  name
	mtd0: 06400000 00040000 "boot"
	mtd1: 06400000 00040000 "kernel"
     ----------------------------------

It is obvious that we lost the truncated partition rootfs which should be 824M in this case.

Why? The old code sets the wrong partitions number when the truncating occurs. This patch fixes it. Alao add a break to shortcut the code in this case.

After apply this patch, the result becomes:

     ----------------------------------
	root@freescale ~$ cat /proc/mtd
	dev:    size   erasesize  name
	mtd0: 06400000 00040000 "boot"
	mtd1: 06400000 00040000 "kernel"
	mtd2: 33800000 00040000 "rootfs"
     ----------------------------------

We get the right result.

---
v1 --> v2:
[1] add more commit info.

---
 drivers/mtd/cmdlinepart.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/mtd/cmdlinepart.c +2 -1
index 4558e0f..fc960a3 100644
@@ -344,7 +344,8 @@ static int parse_cmdline_partitions(struct mtd_info *master,
 					       "%s: partitioning exceeds flash size, truncating\n",
 					       part->mtd_id);
 					part->parts[i].size = master->size - offset;
-					part->num_parts = i;
+					part->num_parts = i + 1;
+					break;
 				}
 				offset += part->parts[i].size;
 			}
Signature · 1 line
1.7.4.4
#1 lore raw

Hi Huang,

drivers/mtd/cmdlinepart.c static int parse_cmdline_partitions(struct mtd_info *master, · line 348

Quoted 11 lines · On Sat, 25 Aug 2012 10:26:07 -0400 Huang Shijie <[email protected]> wrote:
drivers/mtd/cmdlinepart.c +2 -1
index 4558e0f..fc960a3 100644
@@ -344,7 +344,8 @@ static int parse_cmdline_partitions(struct mtd_info *master,
 					       "%s: partitioning exceeds flash size, truncating\n",
 					       part->mtd_id);
 					part->parts[i].size = master->size - offset;
-					part->num_parts = i;
+					part->num_parts = i + 1;
+					break;

Your analysis seems right, but let me offer an alternative approach.

I would simply:

- part->num_parts = i;

(and not replace it with anything).

The specified cmdline partitions might not be ordered (according to start offset), so next partition specified after the truncated one might define a partition at the beginning of the device, which is okay (regardless the truncation of current partition).

Your patch skips the definitions of next partitions, which can be legit.

I agree specifying "unsorted" partitions is not commonly used (and it might make no sense when using the "remaining" syntax), but it is legit to define all partitions _explicitly_ with their size@offset in an unordered fashion.

Regards,
Shmulik

#2 lore raw
Quoted 17 lines · Shmulik Ladkani

Hi Huang,

drivers/mtd/cmdlinepart.c static int parse_cmdline_partitions(struct mtd_info *master, · line 348

Quoted 11 lines · On Sat, 25 Aug 2012 10:26:07 -0400 Huang Shijie <[email protected]> wrote:
drivers/mtd/cmdlinepart.c +2 -1
index 4558e0f..fc960a3 100644
@@ -344,7 +344,8 @@ static int parse_cmdline_partitions(struct mtd_info *master,
                                             "%s: partitioning exceeds flash size, truncating\n",
                                             part->mtd_id);
                                      part->parts[i].size = master->size - offset;
-                                     part->num_parts = i;
+                                     part->num_parts = i + 1;
+                                     break;

Your analysis seems right, but let me offer an alternative approach.

Quoted 3 lines

I would simply:

- part->num_parts = i;

your code does not wors in such kernel command line(also with the 1GB nand chip):
#gpmi-nand:100m(root),100m(kernel),1g(rootfs),1g(user),-(rest)

For you see, we must keep the code robust enough. It should passes all the possible kernel command lines.

Quoted 7 lines

(and not replace it with anything).

The specified cmdline partitions might not be ordered (according to start offset), so next partition specified after the truncated one might define a partition at the beginning of the device, which is okay (regardless the truncation of current partition).

could you please give me an example of this specified cmdline?

I can test it.

Best Regards
Huang Shijie

Quoted 10 lines

Your patch skips the definitions of next partitions, which can be legit.

I agree specifying "unsorted" partitions is not commonly used (and it might make no sense when using the "remaining" syntax), but it is legit to define all partitions _explicitly_ with their size@offset in an unordered fashion.

Regards,
Shmulik

#3 lore raw
Quoted 5 lines · On Sat, 25 Aug 2012 05:26:51 -0400 Huang Shijie <[email protected]> wrote:
Quoted 4 lines

The specified cmdline partitions might not be ordered (according to start offset), so next partition specified after the truncated one might define a partition at the beginning of the device, which is okay (regardless the truncation of current partition).

could you please give me an example of this specified cmdline?

Assume we have a 1GB(8Gb) nand chip:
#gpmi-nand:1g@200m(rootfs),100m@0(boot),100m@100m(kernel)

I am used to explicitly specify size@offset for all my parts.

Obviously I won't define a partition above the device size... somewhat hypothetical discussion here...

But your code will stop after creating 'rootfs' (and original code will not create a single partition).

Is that what we want?

Or do we want to truncate 'rootfs', but still have the valid 'boot' and 'kerner' partitions?

Regards,
Shmulik

#4 lore raw
Quoted 11 lines · Shmulik Ladkani
Quoted 5 lines · On Sat, 25 Aug 2012 05:26:51 -0400 Huang Shijie <[email protected]> wrote:
Quoted 4 lines

The specified cmdline partitions might not be ordered (according to start offset), so next partition specified after the truncated one might define a partition at the beginning of the device, which is okay (regardless the truncation of current partition).

could you please give me an example of this specified cmdline?

Assume we have a 1GB(8Gb) nand chip:
#gpmi-nand:1g@200m(rootfs),100m@0(boot),100m@100m(kernel)

I am used to explicitly specify size@offset for all my parts.

thanks for this example.

I tested it just now.
The current code (without my patch) can not parse out none of the partitions. It directly stops at the first truncated rootfs partition.

I think i should send another patch to sort all the partitions.

thanks a lot.

Huang Shijie

#5 lore raw
In reply to Huang Shijie

Hi,

Quoted 11 lines · On Sat, 25 Aug 2012 05:26:51 -0400 Huang Shijie <[email protected]> wrote:
Quoted 5 lines · Shmulik Ladkani

Your analysis seems right, but let me offer an alternative approach.

I would simply:

- part->num_parts = i;

your code does not wors in such kernel command line(also with the 1GB nand chip):
#gpmi-nand:100m(root),100m(kernel),1g(rootfs),1g(user),-(rest)

Can you please detail what do you mean by "not work"?

To my understanding, in this example, according to my suggestion, the resulting partitions would be:

root 100m@0
kernel 100m@100m
rootfs 800m@200m (truncated)
user 0@1g (truncated)
rest 0@1g

Reasonable IMO, given the fact that the mtd device size is smaller than the specified parts.

I saw you submitted a patch which sorts the cmdline parts; I don't understand why this is necessary.
Also, sorting might not be desirable, as the user specified the unsorted partitions might have _wanted_ them to appear in that order.

Now lets focus on your original suggestion and its consequences:

- Orignal code STOPPED parsing at the 1st truncated partition, this partition WAS NOT returned to the caller
- Your patch STOPS AFTER parsing the 1st truncated partition, this partiton IS returned to the caller (but partitions specified later are no longer parsed)
- My suggestion CONTINUES parsing all partitions.
So later partitions (specified with the 'size' but *without* 'offset') will be truncated AND presented to the caller.
AND, if later partitions are specified using the 'size@offset' explicit format, they are parsed normally.

Regards,
Shmulik

#6 lore raw
Quoted 9 lines · Shmulik Ladkani

Hi,

Quoted 6 lines · On Sat, 25 Aug 2012 05:26:51 -0400 Huang Shijie <[email protected]> wrote:
Quoted 4 lines · Shmulik Ladkani

Your analysis seems right, but let me offer an alternative approach.

I would simply:

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

- part->num_parts = i;

your code does not wors in such kernel command line(also with the 1GB nand chip):
#gpmi-nand:100m(root),100m(kernel),1g(rootfs),1g(user),-(rest)

Can you please detail what do you mean by "not work"?

sorry. :)

My meaning was the result is unreadable. It looks too strange. That's why i use the 'break'
to shortcut the loop.

Quoted 10 lines

To my understanding, in this example, according to my suggestion, the resulting partitions would be:

root    100m@0
kernel  100m@100m
rootfs  800m@200m (truncated)
user    0@1g (truncated)
rest    0@1g

yes, the result is like this.

Quoted 11 lines

Reasonable IMO, given the fact that the mtd device size is smaller than

the specified parts.

I saw you submitted a patch which sorts the cmdline parts; I don't understand why this is necessary.
Also, sorting might not be desirable, as the user specified the unsorted partitions might have _wanted_ them to appear in that order.

Now lets focus on your original suggestion and its consequences:

Quoted 11 lines

- Orignal code STOPPED parsing at the 1st truncated partition, this partition WAS NOT returned to the caller
- Your patch STOPS AFTER parsing the 1st truncated partition, this partiton IS returned to the caller (but partitions specified later are no longer parsed)
- My suggestion CONTINUES parsing all partitions.
So later partitions (specified with the 'size' but *without* 'offset') will be truncated AND presented to the caller.
AND, if later partitions are specified using the 'size@offset' explicit format, they are parsed normally.

Could Artem or David point us a direction about this?
[1] Should the unsorted partitions be supported?
[2] And what should we do when we meet a 1GB nand, and the cmdline is

      gpmi-nand:100m(root),100m(kernel),1g(rootfs),1g(user),-(rest)

thanks a lot
Huang Shijie

#9 lore raw
In reply to Shmulik Ladkani
Quoted 5 lines · Shmulik Ladkani

root 100m@0
kernel 100m@100m
rootfs 800m@200m (truncated)
user 0@1g (truncated)
rest 0@1g

Who would benefit from having those 2 0-sized partitions and how? How many users/scripts would be confused by this (these 2 ghost partitions would be visible in /proc/mtd and sysfs)? How much RAM would we spend for creating sysfs files and directories for these ghost partitions (note, one sysfs file costs a couple KiB I thing, because 'sizeof (struct inode)').

While you suggestion is clever, do we really benefit from this?

Signature · 2 lines
Best Regards,
Artem Bityutskiy
#7 lore raw
In reply to Huang Shijie

While appreciating Shmulik's attention to details, I vote this way:

Quoted 2 lines · Huang Shijie

Could Artem or David point us a direction about this?
[1] Should the unsorted partitions be supported?

No, it is asking for troubles.

Quoted 2 lines

[2] And what should we do when we meet a 1GB nand, and the cmdline is

      gpmi-nand:100m(root),100m(kernel),1g(rootfs),1g(user),-(rest) 

Drop 'user' and 'rest' - I've sent some explanations in the previous e-mail.

Signature · 2 lines
Best Regards,
Artem Bityutskiy
#8 lore raw
Quoted 7 lines · Artem Bityutskiy

While appreciating Shmulik's attention to details, I vote this way:

Quoted 2 lines · Huang Shijie

Could Artem or David point us a direction about this?
[1] Should the unsorted partitions be supported?

No, it is asking for troubles.

thanks.

Quoted 5 lines
Quoted 2 lines

[2] And what should we do when we meet a 1GB nand, and the cmdline is

       gpmi-nand:100m(root),100m(kernel),1g(rootfs),1g(user),-(rest)

Drop 'user' and 'rest' - I've sent some explanations in the previous e-mail.

ok, thanks.

I think this patch is enough to fix this issue.

Huang Shijie

#10 lore raw
In reply to Artem Bityutskiy
Quoted 7 lines · On Wed, 29 Aug 2012 11:16:05 +0300 Artem Bityutskiy <[email protected]> wrote:
Quoted 5 lines · Shmulik Ladkani

root 100m@0
kernel 100m@100m
rootfs 800m@200m (truncated)
user 0@1g (truncated)
rest 0@1g

Quoted 8 lines

Who would benefit from having those 2 0-sized partitions and how? How many users/scripts would be confused by this (these 2 ghost partitions would be visible in /proc/mtd and sysfs)? How much RAM would we spend for creating sysfs files and directories for these ghost partitions (note, one sysfs file costs a couple KiB I thing, because 'sizeof (struct inode)').

While you suggestion is clever, do we really benefit from this?

Artem, please note this is just a side effect of what I've suggested (that its, continue parsing after first truncated partition), not a real use case I'd expect and intentionally wish to support.

I am used to specify partitions explicitly using size@offset (specifying offset for all parts, even if sometimes adjacent), and sometimes in an unsorted fashion.
I never defined some partition that got truncated, so the whole discussion is theoretical to _my_ usecase.

The only benefit of continuing to parse, is that if there _are_ later partitions which are defined _explicitly_ with an offset, whose location is _before_ the truncated partition, these would still be parsed and registered.

Not so important, and would rarely happen, but simplistic and naive.

And reagrding 0 sized partitions, we can always skip these.

Regards,
Shmulik

#11 lore raw
Quoted 5 lines · Shmulik Ladkani
Quoted 1 line

While you suggestion is clever, do we really benefit from this?

Artem, please note this is just a side effect of what I've suggested (that its, continue parsing after first truncated partition), not a real use case I'd expect and intentionally wish to support.

Sorry, I was not reading carefully enough. Could you please recap - are you fine with Huang's latest patch-set or not :) To me sorting and then dropping 0-size partitions looks like a simple and robust approach.

Signature · 2 lines
Best Regards,
Artem Bityutskiy