Re: [systemd-devel] [PATCH] shutdown: avoid calling `kexec` binary unnessecarily

2015-02-17 Thread Shawn Landden
The bootloader spec does not say which entry is to be the default. I cannot
support the spec unless I can choose a single default kernel.

http://freedesktop.org/wiki/Specifications/BootLoaderSpec/

On Tue, Feb 17, 2015 at 7:00 AM, Zbigniew Jędrzejewski-Szmek 
zbys...@in.waw.pl wrote:

 On Mon, Feb 16, 2015 at 07:53:47PM -0800, Shawn Landden wrote:
  On Mon, Feb 16, 2015 at 5:08 AM, Lennart Poettering 
 lenn...@poettering.net
  wrote:
 
   On Fri, 13.02.15 14:18, Shawn Landden (sh...@churchofgit.com) wrote:
  
Still use helper when Xen Dom0, to avoid duplicating some hairy
code.
  
   Hmm, what precisely does the helper do on xen?
  
So we don't have any logic to load kexec kernels?
  
   Currently we don't.
  
   My hope though was that we can make the whole kexec thing work without
   having kexec-tools installed. With the new kernel syscall for loading
   the kernel we should be able to implement this all without any other
   tools.
  
   Ideally we'd not use any external tools anymore, not even in the Xen
   case, hence I am curious what precisely the special hookup for Xen is
   here...?
  
   Lennart
  
  
 
 https://git.kernel.org/cgit/utils/kernel/kexec/kexec-tools.git/tree/kexec/kexec-xen.c
 
  I've attached my patch.
  I'm having a problem with kexec_file_load() returning ENOMEM that I
 havn't
  resolved.
 
   --
   Lennart Poettering, Red Hat
   ___
   systemd-devel mailing list
   systemd-devel@lists.freedesktop.org
   http://lists.freedesktop.org/mailman/listinfo/systemd-devel
  
 
 
 
  --
  Shawn Landden

  From d5446e324143f55e67bc2defe1c78a4ea4201142 Mon Sep 17 00:00:00 2001
  From: Shawn Landden sh...@churchofgit.com
  Date: Fri, 13 Feb 2015 13:48:07 -0800
  Subject: [PATCH] shutdown: avoid calling `kexec` binary unnessecarily
 
  Still use helper when Xen Dom0, to avoid duplicating some hairy code.
  So we don't have any logic to load kexec kernels?
  ---
   TODO |   3 --
   src/core/shutdown.c  | 121
 ++-
   src/shared/missing.h |   7 +++
   3 files changed, 116 insertions(+), 15 deletions(-)
 
  diff --git a/TODO b/TODO
  index 255a4f2..d914d2c 100644
  --- a/TODO
  +++ b/TODO
  @@ -90,9 +90,6 @@ Features:
   * maybe introduce WantsMountsFor=? Usecase:
 
 http://lists.freedesktop.org/archives/systemd-devel/2015-January/027729.html
 
  -* rework kexec logic to use new kexec_file_load() syscall, so that we
  -  don't have to call kexec tool anymore.
  -
   * The udev blkid built-in should expose a property that reflects
 whether media was sensed in USB CF/SD card readers. This should then
 be used to control SYSTEMD_READY=1/0 so that USB card readers aren't
  diff --git a/src/core/shutdown.c b/src/core/shutdown.c
  index 71f001a..14febf3 100644
  --- a/src/core/shutdown.c
  +++ b/src/core/shutdown.c
  @@ -19,6 +19,7 @@
 along with systemd; If not, see http://www.gnu.org/licenses/.
   ***/
 
  +#include ctype.h
   #include sys/mman.h
   #include sys/types.h
   #include sys/reboot.h
  @@ -27,6 +28,7 @@
   #include sys/stat.h
   #include sys/mount.h
   #include sys/syscall.h
  +#include sys/utsname.h
   #include fcntl.h
   #include dirent.h
   #include errno.h
  @@ -138,6 +140,35 @@ static int parse_argv(int argc, char *argv[]) {
   return 0;
   }
 
  +/*
  + * Remove parameter from a kernel command line. Helper function for
 kexec.
  + * (copied from kexec-tools)
  + */
  +static void remove_parameter(char *line, const char *param_name) {
  +char *start, *end;
  +
  +start = strstr(line, param_name);
  +
  +/* parameter not found */
  +if (!start)
  +return;
  +
  +/*
  + * check if that's really the start of a parameter and not in
  + * the middle of the word
  + */
  +if (start != line  !isspace(*(start-1)))
  +return;
  +
  +end = strstr(start,  );
  +if (!end)
  +*start = 0;
  +else {
  +memmove(start, end+1, strlen(end));
  +*(end + strlen(end)) = 0;
  +}
  +}
  +
   static int switch_root_initramfs(void) {
   if (mount(/run/initramfs, /run/initramfs, NULL, MS_BIND,
 NULL)  0)
   return log_error_errno(errno, Failed to mount bind
 /run/initramfs on /run/initramfs: %m);
  @@ -152,6 +183,57 @@ static int switch_root_initramfs(void) {
   return switch_root(/run/initramfs, /oldroot, false,
 MS_BIND);
   }
 
  +static int kernel_load(bool overwrite) {
  +int r = -ENOTSUP;
  +
  +/* only x86_64 and x32 in 3.18 */
  +#ifdef __NR_kexec_file_load
  +/* If uses has no already loaded a kexec kernel assume
 they
  + * want the same one they are currently running. */
  +if (!overwrite  !kexec_loaded()) {
  +struct utsname u;
  +_cleanup_free_ 

Re: [systemd-devel] [PATCH] shutdown: avoid calling `kexec` binary unnessecarily

2015-02-17 Thread Shawn Landden
On Tue, Feb 17, 2015 at 7:00 AM, Zbigniew Jędrzejewski-Szmek 
zbys...@in.waw.pl wrote:

 On Mon, Feb 16, 2015 at 07:53:47PM -0800, Shawn Landden wrote:
  On Mon, Feb 16, 2015 at 5:08 AM, Lennart Poettering 
 lenn...@poettering.net
  wrote:
 
   On Fri, 13.02.15 14:18, Shawn Landden (sh...@churchofgit.com) wrote:
  
Still use helper when Xen Dom0, to avoid duplicating some hairy
code.
  
   Hmm, what precisely does the helper do on xen?
  
So we don't have any logic to load kexec kernels?
  
   Currently we don't.
  
   My hope though was that we can make the whole kexec thing work without
   having kexec-tools installed. With the new kernel syscall for loading
   the kernel we should be able to implement this all without any other
   tools.
  
   Ideally we'd not use any external tools anymore, not even in the Xen
   case, hence I am curious what precisely the special hookup for Xen is
   here...?
  
   Lennart
  
  
 
 https://git.kernel.org/cgit/utils/kernel/kexec/kexec-tools.git/tree/kexec/kexec-xen.c
 
  I've attached my patch.
  I'm having a problem with kexec_file_load() returning ENOMEM that I
 havn't
  resolved.
 
   --
   Lennart Poettering, Red Hat
   ___
   systemd-devel mailing list
   systemd-devel@lists.freedesktop.org
   http://lists.freedesktop.org/mailman/listinfo/systemd-devel
  
 
 
 
  --
  Shawn Landden

  From d5446e324143f55e67bc2defe1c78a4ea4201142 Mon Sep 17 00:00:00 2001
  From: Shawn Landden sh...@churchofgit.com
  Date: Fri, 13 Feb 2015 13:48:07 -0800
  Subject: [PATCH] shutdown: avoid calling `kexec` binary unnessecarily
 
  Still use helper when Xen Dom0, to avoid duplicating some hairy code.
  So we don't have any logic to load kexec kernels?
  ---
   TODO |   3 --
   src/core/shutdown.c  | 121
 ++-
   src/shared/missing.h |   7 +++
   3 files changed, 116 insertions(+), 15 deletions(-)
 
  diff --git a/TODO b/TODO
  index 255a4f2..d914d2c 100644
  --- a/TODO
  +++ b/TODO
  @@ -90,9 +90,6 @@ Features:
   * maybe introduce WantsMountsFor=? Usecase:
 
 http://lists.freedesktop.org/archives/systemd-devel/2015-January/027729.html
 
  -* rework kexec logic to use new kexec_file_load() syscall, so that we
  -  don't have to call kexec tool anymore.
  -
   * The udev blkid built-in should expose a property that reflects
 whether media was sensed in USB CF/SD card readers. This should then
 be used to control SYSTEMD_READY=1/0 so that USB card readers aren't
  diff --git a/src/core/shutdown.c b/src/core/shutdown.c
  index 71f001a..14febf3 100644
  --- a/src/core/shutdown.c
  +++ b/src/core/shutdown.c
  @@ -19,6 +19,7 @@
 along with systemd; If not, see http://www.gnu.org/licenses/.
   ***/
 
  +#include ctype.h
   #include sys/mman.h
   #include sys/types.h
   #include sys/reboot.h
  @@ -27,6 +28,7 @@
   #include sys/stat.h
   #include sys/mount.h
   #include sys/syscall.h
  +#include sys/utsname.h
   #include fcntl.h
   #include dirent.h
   #include errno.h
  @@ -138,6 +140,35 @@ static int parse_argv(int argc, char *argv[]) {
   return 0;
   }
 
  +/*
  + * Remove parameter from a kernel command line. Helper function for
 kexec.
  + * (copied from kexec-tools)
  + */
  +static void remove_parameter(char *line, const char *param_name) {
  +char *start, *end;
  +
  +start = strstr(line, param_name);
  +
  +/* parameter not found */
  +if (!start)
  +return;
  +
  +/*
  + * check if that's really the start of a parameter and not in
  + * the middle of the word
  + */
  +if (start != line  !isspace(*(start-1)))
  +return;
  +
  +end = strstr(start,  );
  +if (!end)
  +*start = 0;
  +else {
  +memmove(start, end+1, strlen(end));
  +*(end + strlen(end)) = 0;
  +}
  +}
  +
   static int switch_root_initramfs(void) {
   if (mount(/run/initramfs, /run/initramfs, NULL, MS_BIND,
 NULL)  0)
   return log_error_errno(errno, Failed to mount bind
 /run/initramfs on /run/initramfs: %m);
  @@ -152,6 +183,57 @@ static int switch_root_initramfs(void) {
   return switch_root(/run/initramfs, /oldroot, false,
 MS_BIND);
   }
 
  +static int kernel_load(bool overwrite) {
  +int r = -ENOTSUP;
  +
  +/* only x86_64 and x32 in 3.18 */
  +#ifdef __NR_kexec_file_load
  +/* If uses has no already loaded a kexec kernel assume
 they
  + * want the same one they are currently running. */
  +if (!overwrite  !kexec_loaded()) {
  +struct utsname u;
  +_cleanup_free_ char *vmlinuz = NULL, *initrd =
 NULL, *cmdline = NULL;
  +_cleanup_close_ int vmlinuz_fd = -1, initrd_fd
 = -1;
  +
  +r = uname(u);
  + 

Re: [systemd-devel] [PATCH] shutdown: avoid calling `kexec` binary unnessecarily

2015-02-17 Thread Shawn Landden
On Tue, Feb 17, 2015 at 4:34 PM, Shawn Landden sh...@churchofgit.com
wrote:

 On Tue, Feb 17, 2015 at 7:00 AM, Zbigniew Jędrzejewski-Szmek 
 zbys...@in.waw.pl wrote:

 On Mon, Feb 16, 2015 at 07:53:47PM -0800, Shawn Landden wrote:
  On Mon, Feb 16, 2015 at 5:08 AM, Lennart Poettering 
 lenn...@poettering.net
  wrote:
 
   On Fri, 13.02.15 14:18, Shawn Landden (sh...@churchofgit.com) wrote:
  
Still use helper when Xen Dom0, to avoid duplicating some hairy
code.
  
   Hmm, what precisely does the helper do on xen?
  
So we don't have any logic to load kexec kernels?
  
   Currently we don't.
  
   My hope though was that we can make the whole kexec thing work without
   having kexec-tools installed. With the new kernel syscall for loading
   the kernel we should be able to implement this all without any other
   tools.
  
   Ideally we'd not use any external tools anymore, not even in the Xen
   case, hence I am curious what precisely the special hookup for Xen is
   here...?
  
   Lennart
  
  
 
 https://git.kernel.org/cgit/utils/kernel/kexec/kexec-tools.git/tree/kexec/kexec-xen.c
 
  I've attached my patch.
  I'm having a problem with kexec_file_load() returning ENOMEM that I
 havn't
  resolved.
 
   --
   Lennart Poettering, Red Hat
   ___
   systemd-devel mailing list
   systemd-devel@lists.freedesktop.org
   http://lists.freedesktop.org/mailman/listinfo/systemd-devel
  
 
 
 
  --
  Shawn Landden

  From d5446e324143f55e67bc2defe1c78a4ea4201142 Mon Sep 17 00:00:00 2001
  From: Shawn Landden sh...@churchofgit.com
  Date: Fri, 13 Feb 2015 13:48:07 -0800
  Subject: [PATCH] shutdown: avoid calling `kexec` binary unnessecarily
 
  Still use helper when Xen Dom0, to avoid duplicating some hairy code.
  So we don't have any logic to load kexec kernels?
  ---
   TODO |   3 --
   src/core/shutdown.c  | 121
 ++-
   src/shared/missing.h |   7 +++
   3 files changed, 116 insertions(+), 15 deletions(-)
 
  diff --git a/TODO b/TODO
  index 255a4f2..d914d2c 100644
  --- a/TODO
  +++ b/TODO
  @@ -90,9 +90,6 @@ Features:
   * maybe introduce WantsMountsFor=? Usecase:
 
 http://lists.freedesktop.org/archives/systemd-devel/2015-January/027729.html
 
  -* rework kexec logic to use new kexec_file_load() syscall, so that we
  -  don't have to call kexec tool anymore.
  -
   * The udev blkid built-in should expose a property that reflects
 whether media was sensed in USB CF/SD card readers. This should then
 be used to control SYSTEMD_READY=1/0 so that USB card readers aren't
  diff --git a/src/core/shutdown.c b/src/core/shutdown.c
  index 71f001a..14febf3 100644
  --- a/src/core/shutdown.c
  +++ b/src/core/shutdown.c
  @@ -19,6 +19,7 @@
 along with systemd; If not, see http://www.gnu.org/licenses/.
   ***/
 
  +#include ctype.h
   #include sys/mman.h
   #include sys/types.h
   #include sys/reboot.h
  @@ -27,6 +28,7 @@
   #include sys/stat.h
   #include sys/mount.h
   #include sys/syscall.h
  +#include sys/utsname.h
   #include fcntl.h
   #include dirent.h
   #include errno.h
  @@ -138,6 +140,35 @@ static int parse_argv(int argc, char *argv[]) {
   return 0;
   }
 
  +/*
  + * Remove parameter from a kernel command line. Helper function for
 kexec.
  + * (copied from kexec-tools)
  + */
  +static void remove_parameter(char *line, const char *param_name) {
  +char *start, *end;
  +
  +start = strstr(line, param_name);
  +
  +/* parameter not found */
  +if (!start)
  +return;
  +
  +/*
  + * check if that's really the start of a parameter and not in
  + * the middle of the word
  + */
  +if (start != line  !isspace(*(start-1)))
  +return;
  +
  +end = strstr(start,  );
  +if (!end)
  +*start = 0;
  +else {
  +memmove(start, end+1, strlen(end));
  +*(end + strlen(end)) = 0;
  +}
  +}
  +
   static int switch_root_initramfs(void) {
   if (mount(/run/initramfs, /run/initramfs, NULL, MS_BIND,
 NULL)  0)
   return log_error_errno(errno, Failed to mount bind
 /run/initramfs on /run/initramfs: %m);
  @@ -152,6 +183,57 @@ static int switch_root_initramfs(void) {
   return switch_root(/run/initramfs, /oldroot, false,
 MS_BIND);
   }
 
  +static int kernel_load(bool overwrite) {
  +int r = -ENOTSUP;
  +
  +/* only x86_64 and x32 in 3.18 */
  +#ifdef __NR_kexec_file_load
  +/* If uses has no already loaded a kexec kernel assume
 they
  + * want the same one they are currently running. */
  +if (!overwrite  !kexec_loaded()) {
  +struct utsname u;
  +_cleanup_free_ char *vmlinuz = NULL, *initrd =
 NULL, *cmdline = NULL;
  +_cleanup_close_ int vmlinuz_fd = -1, 

Re: [systemd-devel] [PATCH] shutdown: avoid calling `kexec` binary unnessecarily

2015-02-17 Thread Zbigniew Jędrzejewski-Szmek
On Tue, Feb 17, 2015 at 04:46:26PM -0800, Shawn Landden wrote:
 The bootloader spec does not say which entry is to be the default. I cannot
 support the spec unless I can choose a single default kernel.
 
 http://freedesktop.org/wiki/Specifications/BootLoaderSpec/
But it says where to look for kernels. Your patch only checks in
/boot directly, but the BLS specifies more directories.

Zbyszek
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [PATCH] shutdown: avoid calling `kexec` binary unnessecarily

2015-02-17 Thread Zbigniew Jędrzejewski-Szmek
On Mon, Feb 16, 2015 at 07:53:47PM -0800, Shawn Landden wrote:
 On Mon, Feb 16, 2015 at 5:08 AM, Lennart Poettering lenn...@poettering.net
 wrote:
 
  On Fri, 13.02.15 14:18, Shawn Landden (sh...@churchofgit.com) wrote:
 
   Still use helper when Xen Dom0, to avoid duplicating some hairy
   code.
 
  Hmm, what precisely does the helper do on xen?
 
   So we don't have any logic to load kexec kernels?
 
  Currently we don't.
 
  My hope though was that we can make the whole kexec thing work without
  having kexec-tools installed. With the new kernel syscall for loading
  the kernel we should be able to implement this all without any other
  tools.
 
  Ideally we'd not use any external tools anymore, not even in the Xen
  case, hence I am curious what precisely the special hookup for Xen is
  here...?
 
  Lennart
 
 
 https://git.kernel.org/cgit/utils/kernel/kexec/kexec-tools.git/tree/kexec/kexec-xen.c
 
 I've attached my patch.
 I'm having a problem with kexec_file_load() returning ENOMEM that I havn't
 resolved.
 
  --
  Lennart Poettering, Red Hat
  ___
  systemd-devel mailing list
  systemd-devel@lists.freedesktop.org
  http://lists.freedesktop.org/mailman/listinfo/systemd-devel
 
 
 
 
 -- 
 Shawn Landden

 From d5446e324143f55e67bc2defe1c78a4ea4201142 Mon Sep 17 00:00:00 2001
 From: Shawn Landden sh...@churchofgit.com
 Date: Fri, 13 Feb 2015 13:48:07 -0800
 Subject: [PATCH] shutdown: avoid calling `kexec` binary unnessecarily
 
 Still use helper when Xen Dom0, to avoid duplicating some hairy code.
 So we don't have any logic to load kexec kernels?
 ---
  TODO |   3 --
  src/core/shutdown.c  | 121 
 ++-
  src/shared/missing.h |   7 +++
  3 files changed, 116 insertions(+), 15 deletions(-)
 
 diff --git a/TODO b/TODO
 index 255a4f2..d914d2c 100644
 --- a/TODO
 +++ b/TODO
 @@ -90,9 +90,6 @@ Features:
  * maybe introduce WantsMountsFor=? Usecase:

 http://lists.freedesktop.org/archives/systemd-devel/2015-January/027729.html
  
 -* rework kexec logic to use new kexec_file_load() syscall, so that we
 -  don't have to call kexec tool anymore.
 -
  * The udev blkid built-in should expose a property that reflects
whether media was sensed in USB CF/SD card readers. This should then
be used to control SYSTEMD_READY=1/0 so that USB card readers aren't
 diff --git a/src/core/shutdown.c b/src/core/shutdown.c
 index 71f001a..14febf3 100644
 --- a/src/core/shutdown.c
 +++ b/src/core/shutdown.c
 @@ -19,6 +19,7 @@
along with systemd; If not, see http://www.gnu.org/licenses/.
  ***/
  
 +#include ctype.h
  #include sys/mman.h
  #include sys/types.h
  #include sys/reboot.h
 @@ -27,6 +28,7 @@
  #include sys/stat.h
  #include sys/mount.h
  #include sys/syscall.h
 +#include sys/utsname.h
  #include fcntl.h
  #include dirent.h
  #include errno.h
 @@ -138,6 +140,35 @@ static int parse_argv(int argc, char *argv[]) {
  return 0;
  }
  
 +/*
 + * Remove parameter from a kernel command line. Helper function for kexec.
 + * (copied from kexec-tools)
 + */
 +static void remove_parameter(char *line, const char *param_name) {
 +char *start, *end;
 +
 +start = strstr(line, param_name);
 +
 +/* parameter not found */
 +if (!start)
 +return;
 +
 +/*
 + * check if that's really the start of a parameter and not in
 + * the middle of the word
 + */
 +if (start != line  !isspace(*(start-1)))
 +return;
 +
 +end = strstr(start,  );
 +if (!end)
 +*start = 0;
 +else {
 +memmove(start, end+1, strlen(end));
 +*(end + strlen(end)) = 0;
 +}
 +}
 +
  static int switch_root_initramfs(void) {
  if (mount(/run/initramfs, /run/initramfs, NULL, MS_BIND, NULL)  
 0)
  return log_error_errno(errno, Failed to mount bind 
 /run/initramfs on /run/initramfs: %m);
 @@ -152,6 +183,57 @@ static int switch_root_initramfs(void) {
  return switch_root(/run/initramfs, /oldroot, false, MS_BIND);
  }
  
 +static int kernel_load(bool overwrite) {
 +int r = -ENOTSUP;
 +
 +/* only x86_64 and x32 in 3.18 */
 +#ifdef __NR_kexec_file_load
 +/* If uses has no already loaded a kexec kernel assume they
 + * want the same one they are currently running. */
 +if (!overwrite  !kexec_loaded()) {
 +struct utsname u;
 +_cleanup_free_ char *vmlinuz = NULL, *initrd = NULL, 
 *cmdline = NULL;
 +_cleanup_close_ int vmlinuz_fd = -1, initrd_fd = -1;
 +
 +r = uname(u);
 +if (r  0)
 +return -errno;
 +
 +vmlinuz = malloc(strlen(/boot/vmlinuz-) + 
 strlen(u.release) + 1);
 +initrd  = 

Re: [systemd-devel] [PATCH] shutdown: avoid calling `kexec` binary unnessecarily

2015-02-16 Thread Shawn Landden
On Mon, Feb 16, 2015 at 5:08 AM, Lennart Poettering lenn...@poettering.net
wrote:

 On Fri, 13.02.15 14:18, Shawn Landden (sh...@churchofgit.com) wrote:

  Still use helper when Xen Dom0, to avoid duplicating some hairy
  code.

 Hmm, what precisely does the helper do on xen?

  So we don't have any logic to load kexec kernels?

 Currently we don't.

 My hope though was that we can make the whole kexec thing work without
 having kexec-tools installed. With the new kernel syscall for loading
 the kernel we should be able to implement this all without any other
 tools.

 Ideally we'd not use any external tools anymore, not even in the Xen
 case, hence I am curious what precisely the special hookup for Xen is
 here...?

 Lennart


https://git.kernel.org/cgit/utils/kernel/kexec/kexec-tools.git/tree/kexec/kexec-xen.c

I've attached my patch.
I'm having a problem with kexec_file_load() returning ENOMEM that I havn't
resolved.

 --
 Lennart Poettering, Red Hat
 ___
 systemd-devel mailing list
 systemd-devel@lists.freedesktop.org
 http://lists.freedesktop.org/mailman/listinfo/systemd-devel




-- 
Shawn Landden
From d5446e324143f55e67bc2defe1c78a4ea4201142 Mon Sep 17 00:00:00 2001
From: Shawn Landden sh...@churchofgit.com
Date: Fri, 13 Feb 2015 13:48:07 -0800
Subject: [PATCH] shutdown: avoid calling `kexec` binary unnessecarily

Still use helper when Xen Dom0, to avoid duplicating some hairy code.
So we don't have any logic to load kexec kernels?
---
 TODO |   3 --
 src/core/shutdown.c  | 121 ++-
 src/shared/missing.h |   7 +++
 3 files changed, 116 insertions(+), 15 deletions(-)

diff --git a/TODO b/TODO
index 255a4f2..d914d2c 100644
--- a/TODO
+++ b/TODO
@@ -90,9 +90,6 @@ Features:
 * maybe introduce WantsMountsFor=? Usecase:
   http://lists.freedesktop.org/archives/systemd-devel/2015-January/027729.html
 
-* rework kexec logic to use new kexec_file_load() syscall, so that we
-  don't have to call kexec tool anymore.
-
 * The udev blkid built-in should expose a property that reflects
   whether media was sensed in USB CF/SD card readers. This should then
   be used to control SYSTEMD_READY=1/0 so that USB card readers aren't
diff --git a/src/core/shutdown.c b/src/core/shutdown.c
index 71f001a..14febf3 100644
--- a/src/core/shutdown.c
+++ b/src/core/shutdown.c
@@ -19,6 +19,7 @@
   along with systemd; If not, see http://www.gnu.org/licenses/.
 ***/
 
+#include ctype.h
 #include sys/mman.h
 #include sys/types.h
 #include sys/reboot.h
@@ -27,6 +28,7 @@
 #include sys/stat.h
 #include sys/mount.h
 #include sys/syscall.h
+#include sys/utsname.h
 #include fcntl.h
 #include dirent.h
 #include errno.h
@@ -138,6 +140,35 @@ static int parse_argv(int argc, char *argv[]) {
 return 0;
 }
 
+/*
+ * Remove parameter from a kernel command line. Helper function for kexec.
+ * (copied from kexec-tools)
+ */
+static void remove_parameter(char *line, const char *param_name) {
+char *start, *end;
+
+start = strstr(line, param_name);
+
+/* parameter not found */
+if (!start)
+return;
+
+/*
+ * check if that's really the start of a parameter and not in
+ * the middle of the word
+ */
+if (start != line  !isspace(*(start-1)))
+return;
+
+end = strstr(start,  );
+if (!end)
+*start = 0;
+else {
+memmove(start, end+1, strlen(end));
+*(end + strlen(end)) = 0;
+}
+}
+
 static int switch_root_initramfs(void) {
 if (mount(/run/initramfs, /run/initramfs, NULL, MS_BIND, NULL)  0)
 return log_error_errno(errno, Failed to mount bind /run/initramfs on /run/initramfs: %m);
@@ -152,6 +183,57 @@ static int switch_root_initramfs(void) {
 return switch_root(/run/initramfs, /oldroot, false, MS_BIND);
 }
 
+static int kernel_load(bool overwrite) {
+int r = -ENOTSUP;
+
+/* only x86_64 and x32 in 3.18 */
+#ifdef __NR_kexec_file_load
+/* If uses has no already loaded a kexec kernel assume they
+ * want the same one they are currently running. */
+if (!overwrite  !kexec_loaded()) {
+struct utsname u;
+_cleanup_free_ char *vmlinuz = NULL, *initrd = NULL, *cmdline = NULL;
+_cleanup_close_ int vmlinuz_fd = -1, initrd_fd = -1;
+
+r = uname(u);
+if (r  0)
+return -errno;
+
+vmlinuz = malloc(strlen(/boot/vmlinuz-) + strlen(u.release) + 1);
+initrd  = malloc(strlen(/boot/initrd.img-) + strlen(u.release) + 1);
+if (!vmlinuz || !initrd)
+return -ENOMEM;
+
+r = read_one_line_file(/proc/cmdline, cmdline);
+ 

Re: [systemd-devel] [PATCH] shutdown: avoid calling `kexec` binary unnessecarily

2015-02-16 Thread Lennart Poettering
On Fri, 13.02.15 14:18, Shawn Landden (sh...@churchofgit.com) wrote:

 Still use helper when Xen Dom0, to avoid duplicating some hairy
 code.

Hmm, what precisely does the helper do on xen?

 So we don't have any logic to load kexec kernels?

Currently we don't.

My hope though was that we can make the whole kexec thing work without
having kexec-tools installed. With the new kernel syscall for loading
the kernel we should be able to implement this all without any other
tools.

Ideally we'd not use any external tools anymore, not even in the Xen
case, hence I am curious what precisely the special hookup for Xen is
here...? 

Lennart

-- 
Lennart Poettering, Red Hat
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [PATCH] shutdown: avoid calling `kexec` binary unnessecarily

2015-02-14 Thread Zbigniew Jędrzejewski-Szmek
On Fri, Feb 13, 2015 at 02:18:07PM -0800, Shawn Landden wrote:
 Still use helper when Xen Dom0, to avoid duplicating some hairy code.
 So we don't have any logic to load kexec kernels?
 ---
  TODO|  3 ---
  src/core/shutdown.c | 33 -
  2 files changed, 20 insertions(+), 16 deletions(-)
 
 diff --git a/TODO b/TODO
 index 883b994..68b0af6 100644
 --- a/TODO
 +++ b/TODO
 @@ -85,9 +85,6 @@ Features:
  * maybe introduce WantsMountsFor=? Usecase:

 http://lists.freedesktop.org/archives/systemd-devel/2015-January/027729.html
  
 -* rework kexec logic to use new kexec_file_load() syscall, so that we
 -  don't have to call kexec tool anymore.
You patch does not really change this. We can still use kexec_file_load() to
load a kernel. But removing a call to kexec to actually do the reboot seems 
good.
So I guess this TODO item should stay.

One comment below.

  * The udev blkid built-in should expose a property that reflects
whether media was sensed in USB CF/SD card readers. This should then
be used to control SYSTEMD_READY=1/0 so that USB card readers aren't
 diff --git a/src/core/shutdown.c b/src/core/shutdown.c
 index 71f001a..c64c05d 100644
 --- a/src/core/shutdown.c
 +++ b/src/core/shutdown.c
 @@ -350,26 +350,33 @@ int main(int argc, char *argv[]) {
  case LINUX_REBOOT_CMD_KEXEC:
  
  if (!in_container) {
 -/* We cheat and exec kexec to avoid doing all its 
 work */
 -pid_t pid;
 +_cleanup_free_ char *param = NULL;
  
  log_info(Rebooting with kexec.);
  
 -pid = fork();
 -if (pid  0)
 -log_error_errno(errno, Failed to fork: %m);
 -else if (pid == 0) {
 +/* kexec-tools has a bunch of special code to make 
 Xen Dom0 work,
 + * otherwise it is only doing stuff we have already 
 done */
 +if (access(/proc/xen, F_OK) == 0) {
Wouldn't it be better to use detect_virtualization() here instead of 
open-coding the check?

 +pid_t pid;
 +
 +pid = fork();
 +if (pid  0)
 +log_error_errno(errno, Failed to 
 fork: %m);
 +else if (pid == 0) {
 +
 +const char * const args[] = {
 +KEXEC, -e, NULL
 +};
  
 -const char * const args[] = {
 -KEXEC, -e, NULL
 -};
 +/* Child */
  
 -/* Child */
 +execv(args[0], (char * const *) 
 args);
 +_exit(EXIT_FAILURE);
 +} else
 +wait_for_terminate_and_warn(kexec, 
 pid, true);
  
 -execv(args[0], (char * const *) args);
 -_exit(EXIT_FAILURE);
  } else
 -wait_for_terminate_and_warn(kexec, pid, 
 true);
 +reboot(cmd);
  }
  
  cmd = RB_AUTOBOOT;

Zbyszek
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [PATCH] shutdown: avoid calling `kexec` binary unnessecarily

2015-02-14 Thread Zbigniew Jędrzejewski-Szmek
On Sat, Feb 14, 2015 at 10:00:54AM -0800, Shawn Landden wrote:
 On Sat, Feb 14, 2015 at 5:54 AM, Zbigniew Jędrzejewski-Szmek 
 zbys...@in.waw.pl wrote:
 
  On Fri, Feb 13, 2015 at 02:18:07PM -0800, Shawn Landden wrote:
   Still use helper when Xen Dom0, to avoid duplicating some hairy code.
   So we don't have any logic to load kexec kernels?
   ---
TODO|  3 ---
src/core/shutdown.c | 33 -
2 files changed, 20 insertions(+), 16 deletions(-)
  
   diff --git a/TODO b/TODO
   index 883b994..68b0af6 100644
   --- a/TODO
   +++ b/TODO
   @@ -85,9 +85,6 @@ Features:
* maybe introduce WantsMountsFor=? Usecase:
  
  http://lists.freedesktop.org/archives/systemd-devel/2015-January/027729.html
  
   -* rework kexec logic to use new kexec_file_load() syscall, so that we
   -  don't have to call kexec tool anymore.
  You patch does not really change this. We can still use kexec_file_load()
  to
  load a kernel. But removing a call to kexec to actually do the reboot
  seems good.
  So I guess this TODO item should stay.
 
 I would be happy to change that, but I couldn't find any uses of
 kexec_load() or any other calls to the kexec binary in systemd's git.
I think we should try to load the kernel when 'systemctl kexec' is invoked.
Current behaviour of silently falling through to reboot is annoying.

  One comment below.
 
* The udev blkid built-in should expose a property that reflects
  whether media was sensed in USB CF/SD card readers. This should then
  be used to control SYSTEMD_READY=1/0 so that USB card readers aren't
   diff --git a/src/core/shutdown.c b/src/core/shutdown.c
   index 71f001a..c64c05d 100644
   --- a/src/core/shutdown.c
   +++ b/src/core/shutdown.c
   @@ -350,26 +350,33 @@ int main(int argc, char *argv[]) {
case LINUX_REBOOT_CMD_KEXEC:
  
if (!in_container) {
   -/* We cheat and exec kexec to avoid doing all
  its work */
   -pid_t pid;
   +_cleanup_free_ char *param = NULL;
  
log_info(Rebooting with kexec.);
  
   -pid = fork();
   -if (pid  0)
   -log_error_errno(errno, Failed to fork:
  %m);
   -else if (pid == 0) {
   +/* kexec-tools has a bunch of special code to
  make Xen Dom0 work,
   + * otherwise it is only doing stuff we have
  already done */
   +if (access(/proc/xen, F_OK) == 0) {
  Wouldn't it be better to use detect_virtualization() here instead of
  open-coding the check?
 
  That would be *way* more code, and I don't have a xen system to check if
 that detects Dom0, which is all that we are interested in (otherwise kexec
 doesn't work in virtualized environments.)
I think your test detects Dom0 and also DomU. detect_virtualization() only
detects (or should only detect) DomU. So d_v() is wrong for this usecase.

So I think your patch is fine, but a comment should be added explaining
that the test is imprecise and covers all xen domains, but this is OK, since
the fallback to real kexec is OK.

Zbyszek
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel