Michael Tautschnig <m...@debian.org> wrote:

Hi,

>> Currently, unless I missed something, the only way to have tmpfs
>> filesystems set up during the installation is to use a hook to add them
>> directly to the fstab before mounting partitions.
>
> I first thought we could somehow make it as simple as specifying tmpfs as file
> system, but no, that doesn't really work and requires a lot more hacks.

Yes, it really doesn't fit well in anything we currently have.

>> tmpfs   /foo    30%     defaults
>> 
>> Here, the percentage is relative to the amount of RAM installed in the
>> machine; it's used directly as a parameter for the tmpfs mount
>> (size=30%).
>
> Together with the percentage-of-RAM-size patch I'd prefer if RAM:X% was also
> used in here.

That was an open question on my end, adding the prefix isn't necessary
but it makes it very clear what we're talking about. Added in the
attached patch.

> Maybe it should even be invalid without RAM:?

It is now :)

> Is the first column good for anything? Could we have anything else
> than "tmpfs" in there?

It seems a bit more future-proof with this in; maybe we'll have to
extend this to handle other RAM-based filesystems in the future.

Also, not sure how well the parser would cope without it, could be a
problem.

>> If you specify either of size= or nr_blocks= in the mount options for
>> the tmpfs filesystem, the size given in the 3rd column will be silently
>> ignored in favour of the size given in the mount options (used
>> unchanged).
>
> I think some warning would be nice in those cases.

Yes, added.

> See above :-) And well, yes, documentation patches would be appreciated :-)

Added too :)

> Honestly, I haven't really reviewed the patch itself. Could you maybe first
> comment on my comments or even update the patch (and add documentation)?

Here it is, version 2.

JB.

-- 
 Julien BLACHE <jbla...@debian.org>  |  Debian, because code matters more 
 Debian & GNU/Linux Developer        |       <http://www.debian.org>
 Public key available on <http://www.jblache.org> - KeyID: F5D6 5169 
 GPG Fingerprint : 935A 79F1 C8B3 3521 FD62 7CC7 CD61 4FD7 F5D6 5169 

diff -ru a/lib/setup-storage/Commands.pm b/lib/setup-storage/Commands.pm
--- a/lib/setup-storage/Commands.pm	2010-04-05 14:39:33.000000000 +0200
+++ b/lib/setup-storage/Commands.pm	2010-05-10 14:33:57.000000000 +0200
@@ -235,8 +235,8 @@
 sub build_raid_commands {
 
   foreach my $config (keys %FAI::configs) { # loop through all configs
-    # no LVM or physical devices here
-    next if ($config eq "CRYPT" || $config =~ /^VG_./ || $config =~ /^PHY_./);
+    # no encrypted, tmpfs, LVM or physical devices here
+    next if ($config eq "CRYPT" || $config eq "TMPFS" || $config =~ /^VG_./ || $config =~ /^PHY_./);
     ($config eq "RAID") or &FAI::internal_error("Invalid config $config");
 
     # create all raid devices
@@ -522,8 +522,8 @@
   # loop through all configs
   foreach my $config (keys %FAI::configs) {
 
-    # no physical devices, RAID or encrypted here
-    next if ($config =~ /^PHY_./ || $config eq "RAID" || $config eq "CRYPT");
+    # no physical devices, RAID, encrypted or tmpfs here
+    next if ($config =~ /^PHY_./ || $config eq "RAID" || $config eq "CRYPT" || $config eq "TMPFS");
     ($config =~ /^VG_(.+)$/) or &FAI::internal_error("Invalid config $config");
     next if ($1 eq "--ANY--");
     my $vg = $1; # the volume group
@@ -931,8 +931,8 @@
 
   # loop through all configs
   foreach my $config ( keys %FAI::configs ) {
-    # no RAID, encrypted or LVM devices here
-    next if ($config eq "RAID" || $config eq "CRYPT" || $config =~ /^VG_./);
+    # no RAID, encrypted, tmpfs or LVM devices here
+    next if ($config eq "RAID" || $config eq "CRYPT" || $config eq "TMPFS" || $config =~ /^VG_./);
     ($config =~ /^PHY_(.+)$/) or &FAI::internal_error("Invalid config $config");
     my $disk = $1; # the device to be configured
 
diff -ru a/lib/setup-storage/Fstab.pm b/lib/setup-storage/Fstab.pm
--- a/lib/setup-storage/Fstab.pm	2010-04-05 14:39:33.000000000 +0200
+++ b/lib/setup-storage/Fstab.pm	2010-05-27 10:59:16.000000000 +0200
@@ -58,9 +58,10 @@
   push @fstab_line, ($d_ref->{mountpoint}, $d_ref->{filesystem},
     $d_ref->{mount_options}, 0, 2);
   # order of filesystem checks: the root filesystem gets a 1, the others
-  # get 2, swap gets 0
+  # get 2, swap and tmpfs get 0
   $fstab_line[-1] = 1 if ($d_ref->{mountpoint} eq "/");
   $fstab_line[-1] = 0 if ($d_ref->{filesystem} eq "swap");
+  $fstab_line[-1] = 0 if ($d_ref->{filesystem} eq "tmpfs");
 
   # set the ROOT_PARTITION variable, if this is the mountpoint for /
   $FAI::disk_var{ROOT_PARTITION} = $name
@@ -270,8 +271,28 @@
 
         push @fstab, &FAI::create_fstab_line($c_ref, $device_name, $device_name);
       }
+    } elsif ($c eq "TMPFS") {
+      foreach my $v (keys %{ $config->{$c}->{volumes} }) {
+        my $c_ref = $config->{$c}->{volumes}->{$v};
+
+        next if ($c_ref->{mountpoint} eq "-");
+
+        ($c_ref->{mountpoint} eq "/boot" || ($c_ref->{mountpoint} eq "/" &&
+            !defined ($FAI::disk_var{BOOT_PARTITION}))) and
+          die "Boot partition cannot be a tmpfs\n";
+
+	if (($c_ref->{mount_options} =~ m/size=/) || ($c_ref->{mount_options} =~ m/nr_blocks=/)) {
+          warn "Specified tmpfs size for $c_ref->{mountpoint} ignored as mount options contain size= or nr_blocks=\n";
+        } else {
+	  $c_ref->{mount_options} .= "," if ($c_ref->{mount_options} ne "");
+          # Size will be in % or MiB
+	  $c_ref->{mount_options} .= "size=" . $c_ref->{size};
+	}
+
+        push @fstab, &FAI::create_fstab_line($c_ref, "tmpfs", "tmpfs");
+      }
     } else {
-      &FAI::internal_error("Unexpected key $c");
+      &FAI::internal_error("Fstab.pm: Unexpected key $c");
     }
   }
 
diff -ru a/lib/setup-storage/Parser.pm b/lib/setup-storage/Parser.pm
--- a/lib/setup-storage/Parser.pm	2010-04-05 14:39:33.000000000 +0200
+++ b/lib/setup-storage/Parser.pm	2010-05-27 10:56:40.000000000 +0200
@@ -375,6 +375,12 @@
           # exit config mode
           $FAI::device = "";
         }
+        | /^tmpfs/
+        {
+          $FAI::device = "TMPFS";
+          $FAI::configs{$FAI::device}{fstabkey} = "device";
+          $FAI::configs{$FAI::device}{volumes} = {};
+        }
         | /^disk(\d+)/
         {
           # check, whether parted is available
@@ -560,6 +566,26 @@
           $FAI::partition_pointer = (\%FAI::configs)->{CRYPT}->{volumes}->{$vol_id};
         }
         mountpoint devices filesystem mount_options lv_or_fsopts
+        | /^tmpfs\s+/
+        {
+          ($FAI::device eq "TMPFS") or die "tmpfs entry invalid in this context\n";
+          defined ($FAI::configs{TMPFS}) or &FAI::internal_error("TMPFS entry missing");
+
+          my $vol_id = 0;
+          foreach my $ex_vol_id (&FAI::numsort(keys %{ $FAI::configs{TMPFS}{volumes} })) {
+            defined ($FAI::configs{TMPFS}{volumes}{$ex_vol_id}{device}) or last;
+            $vol_id++;
+          }
+
+          $FAI::configs{TMPFS}{volumes}{$vol_id}{device} = "tmpfs";
+          $FAI::configs{TMPFS}{volumes}{$vol_id}{filesystem} = "tmpfs";
+
+          # We don't do preserve for tmpfs
+          $FAI::configs{TMPFS}{volumes}{$vol_id}{preserve} = 0;
+
+          $FAI::partition_pointer = (\%FAI::configs)->{TMPFS}->{volumes}->{$vol_id};
+        }
+        mountpoint tmpfs_size mount_options
         | type mountpoint size filesystem mount_options lv_or_fsopts
 
     type: 'primary'
@@ -682,6 +708,27 @@
         }
         | <error: invalid partition size near "$text">
 
+    tmpfs_size: /^(RAM:(\d+%)|\d+[kMGTPiB]*)\s+/
+        {
+          my $size;
+
+          # convert the units, if necessary
+          # A percentage is kept as is as tmpfs handles it
+          if (defined($2)) {
+            $size = $2;
+          } else {
+            $size = $1;
+            $size .= "MiB" if ($size =~ /\d\s*$/);
+            $size  = &FAI::convert_unit($size);
+            # Size in MiB for tmpfs
+            $size .= "m";
+          }
+
+          # enter the size into the hash
+          $FAI::partition_pointer->{size} = $size;
+        }
+        | <error: invalid tmpfs size near "$text">
+
     devices: /^([^\d,:\s\-][^,:\s]*(:(spare|missing))*(,[^,:\s]+(:(spare|missing))*)*)/
         {
           # split the device list by ,
diff -ru a/lib/setup-storage/Sizes.pm b/lib/setup-storage/Sizes.pm
--- a/lib/setup-storage/Sizes.pm	2010-04-05 14:39:33.000000000 +0200
+++ b/lib/setup-storage/Sizes.pm	2010-05-10 14:31:16.000000000 +0200
@@ -201,8 +201,8 @@
   # loop through all device configurations
   foreach my $config (keys %FAI::configs) {
 
-    # for RAID, encrypted or physical disks there is nothing to be done here
-    next if ($config eq "RAID" || $config eq "CRYPT" || $config =~ /^PHY_./);
+    # for RAID, encrypted, tmpfs or physical disks there is nothing to be done here
+    next if ($config eq "RAID" || $config eq "CRYPT" || $config eq "TMPFS" || $config =~ /^PHY_./);
     ($config =~ /^VG_(.+)$/) or &FAI::internal_error("invalid config entry $config");
     next if ($1 eq "--ANY--");
     my $vg = $1; # the volume group name
@@ -611,8 +611,8 @@
   # loop through all device configurations
   foreach my $config (keys %FAI::configs) {
 
-    # for RAID, encrypted or LVM, there is nothing to be done here
-    next if ($config eq "RAID" || $config eq "CRYPT" || $config =~ /^VG_./);
+    # for RAID, encrypted, tmpfs or LVM, there is nothing to be done here
+    next if ($config eq "RAID" || $config eq "CRYPT" || $config eq "TMPFS" || $config =~ /^VG_./);
     ($config =~ /^PHY_(.+)$/) or &FAI::internal_error("invalid config entry $config");
     # nothing to be done, if this is a configuration for a virtual disk
     next if $FAI::configs{$config}{virtual};
diff -ru a/lib/setup-storage/Volumes.pm b/lib/setup-storage/Volumes.pm
--- a/lib/setup-storage/Volumes.pm	2010-04-05 14:39:33.000000000 +0200
+++ b/lib/setup-storage/Volumes.pm	2010-05-10 14:23:35.000000000 +0200
@@ -462,8 +462,11 @@
     } elsif ($config eq "CRYPT") {
       # We don't do preserve for encrypted partitions
       next;
+    } elsif ($config eq "TMPFS") {
+      # We don't do preserve for tmpfs
+      next;
     } else {
-      &FAI::internal_error("Unexpected key $config");
+      &FAI::internal_error("Volumes.pm: Unexpected key $config");
     }
   }
 }
diff -ru a/man/setup-storage.8 b/man/setup-storage.8
--- a/man/setup-storage.8	2010-05-27 11:23:18.000000000 +0200
+++ b/man/setup-storage.8	2010-05-27 11:24:05.000000000 +0200
@@ -138,6 +138,8 @@
 .br
            | disk_config cryptsetup( <cryptsetupoption>)*
 .br
+           | disk_config tmpfs
+.br
            | disk_config end 
 .br
            | disk_config disk[[:digit:]]+( <option>)*
@@ -266,6 +268,10 @@
 .br
            /* lvm vg */
 .br
+           | tmpfs <mountpoint> <tmpfs_size> <mount_options>
+.br
+           /* tmpfs volume */
+.br
 
 
 type ::= primary
@@ -344,6 +350,14 @@
 .br
 
 
+tmpfs_size ::= (RAM:[[:digit:]]+%|[[:digit:]]+[kKMGTPiB]*)
+.br
+         /* tmpfs size in percentage of the total RAM or fixed size in
+.br
+          kilo (KiB), mega (default, MiB), giga (GiB), tera (TiB) or petabytes (PiB).
+.br
+
+
 mount_options ::= [^[:space:]]+
 .br
 

Reply via email to