public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
From: Tobias Bading <tbading@web.de>
To: libc-help@sourceware.org
Subject: Re: (stat(...) == -1 || faccessat(...) == -1) && errno == EINTR ?!??
Date: Mon, 15 Feb 2021 09:33:28 +0100	[thread overview]
Message-ID: <1be061bd-7d45-eaeb-479a-b4e7aed65525@web.de> (raw)
In-Reply-To: <a445feab-69b8-2d3c-7223-2088c53263f4@web.de>

[-- Attachment #1: Type: text/plain, Size: 1710 bytes --]

Update:
I've pimped the test program a bit and ran it against a local CIFS share
like Konstantin did.

Output of some of my test runs:

$ ./its-raining-signals /mnt/shared 100
100 signals during 747470 loop iterations
100 signals during 752470 loop iterations
100 signals during 733729 loop iterations
100 signals during 754084 loop iterations
100 signals during 746603 loop iterations
stat() failed: Interrupted system call

$ ./its-raining-signals /mnt/shared 1000
1000 signals during 746063 loop iterations
stat() failed: Interrupted system call

$ ./its-raining-signals /mnt/shared 10000
stat() failed: Interrupted system call

$ ./its-raining-signals /mnt/shared 1000 r
1000 signals during 724637 loop iterations
1000 signals during 749337 loop iterations
1000 signals during 747301 loop iterations
[... keeps on going, no errors ...]

$ ./its-raining-signals /mnt/shared 10000 r
[no output, hangs]

These are the two CIFS-related kernel patches I've found so far:
- cifs: handle -EINTR in cifs_setattr
https://github.com/torvalds/linux/commit/c6cc4c5a72505a0ecefc9b413f16bec512f38078
   (earliest linux-stable tag including the patch: v5.10-rc1)
- cifs: do not fail __smb_send_rqst if non-fatal signals are pending
   (already mentioned by Godmar)
https://github.com/torvalds/linux/commit/214a5ea081e77346e4963dd6d20c5539ff8b6ae6
   (earliest linux-stable tag including the patch: v5.11-rc5)

If I checked the Ubuntu focal git repo correctly, both commits aren't in
there, so apparently no backports yet in Ubuntu.

I'll check how much effort it is to install a newer mainline kernel
(including the kernel modules like cifs.ko) in Ubuntu focal.

Tobias


[-- Attachment #2: its-raining-signals.c --]
[-- Type: text/x-csrc, Size: 1906 bytes --]

#define _GNU_SOURCE
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>

static long handler_calls, loop_iterations;

#define TEST_STAT stat (path, &st)
#define TEST_FACCESSAT faccessat (AT_FDCWD, path, R_OK, 0)

void handler (int signum)
{
  ++handler_calls;
}

int main (int argc, char *argv[])
{
  const char *path;
  long signals_per_second;
  int retry = 0;
  struct stat st;
  struct sigaction action;
  struct itimerval timer;

  if (argc < 3)
  {
    printf ("usage: %s PATH-TO-SHARE SIGNALS-PER-SECOND [r]\n"
            "       SIGNALS-PER-SECOND between 2 and 1 million\n"
            "       r repeats a call when errno is EINTR\n", argv[0]);
    return 1;
  }

  path = argv[1];
  signals_per_second = strtol (argv[2], NULL, 0);
  if (argc >= 4 && !strcmp (argv[3], "r"))
    retry = 1;

  memset (&action, 0, sizeof action);
  action.sa_handler = handler;
  action.sa_flags = SA_RESTART;
  if (sigaction (SIGALRM, &action, NULL))
  {
    perror ("sigaction() failed");
    return 1;
  }

  timer.it_value.tv_sec  = timer.it_interval.tv_sec  = 0;
  timer.it_value.tv_usec = timer.it_interval.tv_usec = 1000000 / signals_per_second;
  if (setitimer (ITIMER_REAL, &timer, NULL))
  {
    perror ("setitimer() failed");
    return 1;
  }

  for (;;)
  {
    if (retry ? TEMP_FAILURE_RETRY (TEST_STAT) : TEST_STAT)
    {
      perror ("stat() failed");
      return 1;
    }

    if (retry ? TEMP_FAILURE_RETRY (TEST_FACCESSAT) : TEST_FACCESSAT)
    {
      perror ("faccessat() failed");
      return 1;
    }

    ++loop_iterations;

    if (handler_calls >= signals_per_second)
    {
      printf ("%ld signals during %ld loop iterations\n", handler_calls, loop_iterations);
      handler_calls = loop_iterations = 0;
    }
  }

  return 0;
}

  parent reply	other threads:[~2021-02-15  8:33 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-14 11:13 Tobias Bading
2021-02-14 12:18 ` Tobias Bading
2021-02-14 13:17   ` Tobias Bading
2021-02-14 15:14     ` Godmar Back
2021-02-14 15:20       ` Godmar Back
2021-02-14 17:30       ` Tobias Bading
2021-02-14 22:04         ` Godmar Back
2021-02-15  9:15           ` Tobias Bading
2021-02-15  9:24             ` Florian Weimer
2021-02-15  9:43               ` Tobias Bading
2021-02-15  9:45                 ` Florian Weimer
2021-02-15 10:02                   ` Tobias Bading
2021-02-15 10:20                     ` Florian Weimer
2021-02-15 10:36                       ` Tobias Bading
2021-02-15  8:33         ` Tobias Bading [this message]
2021-02-15  8:45           ` Konstantin Kharlamov
2021-02-15 10:25             ` Tobias Bading
2021-02-14 17:56   ` Konstantin Kharlamov
2021-02-14 18:58     ` Tobias Bading
2021-02-14 20:46       ` Konstantin Kharlamov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1be061bd-7d45-eaeb-479a-b4e7aed65525@web.de \
    --to=tbading@web.de \
    --cc=libc-help@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).