"Fossies" - the Fresh Open Source Software Archive

Member "stress-ng-0.09.56/stress-sysinfo.c" (15 Mar 2019, 4524 Bytes) of package /linux/privat/stress-ng-0.09.56.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "stress-sysinfo.c" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 0.09.50_vs_0.09.51.

    1 /*
    2  * Copyright (C) 2013-2019 Canonical, Ltd.
    3  *
    4  * This program is free software; you can redistribute it and/or
    5  * modify it under the terms of the GNU General Public License
    6  * as published by the Free Software Foundation; either version 2
    7  * of the License, or (at your option) any later version.
    8  *
    9  * This program is distributed in the hope that it will be useful,
   10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12  * GNU General Public License for more details.
   13  *
   14  * You should have received a copy of the GNU General Public License
   15  * along with this program; if not, write to the Free Software
   16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
   17  *
   18  * This code is a complete clean re-write of the stress tool by
   19  * Colin Ian King <colin.king@canonical.com> and attempts to be
   20  * backwardly compatible with the stress tool by Amos Waterland
   21  * <apw@rossby.metr.ou.edu> but has more stress tests and more
   22  * functionality.
   23  *
   24  */
   25 #include "stress-ng.h"
   26 
   27 #define check_do_run()          \
   28     if (!g_keep_stressing_flag) \
   29         break;          \
   30 
   31 /*
   32  *  stress on system information
   33  *  stress system by rapid fetches of system information
   34  */
   35 static int stress_sysinfo(const args_t *args)
   36 {
   37     int n_mounts;
   38     char *mnts[128];
   39 
   40     (void)memset(mnts, 0, sizeof(mnts));
   41 
   42     n_mounts = mount_get(mnts, SIZEOF_ARRAY(mnts));
   43     if (n_mounts < 0) {
   44         pr_err("%s: failed to get mount points\n", args->name);
   45         return EXIT_FAILURE;
   46     }
   47     if (args->instance == 0)
   48         pr_dbg("%s: found %d mount points\n",
   49             args->name, n_mounts);
   50 
   51     do {
   52         struct tms tms_buf;
   53         clock_t clk;
   54 #if defined(HAVE_SYS_SYSINFO_H) &&  \
   55     defined(HAVE_SYSINFO) &&        \
   56     defined(HAVE_SYS_STATFS_H)
   57         {
   58             struct sysinfo sysinfo_buf;
   59             struct statfs statfs_buf;
   60             int i, ret;
   61 
   62             ret = sysinfo(&sysinfo_buf);
   63             if ((ret < 0) && (g_opt_flags & OPT_FLAGS_VERIFY))
   64                 pr_fail_err("sysinfo");
   65 
   66             check_do_run();
   67 
   68             /* Linux statfs variant */
   69             for (i = 0; i < n_mounts; i++) {
   70                 int fd;
   71 
   72                 check_do_run();
   73 
   74                 if (!mnts[i])
   75                     continue;
   76 
   77                 ret = statfs(mnts[i], &statfs_buf);
   78                 /* Mount may have been removed, so purge it */
   79                 if ((ret < 0) && (errno == ENOENT)) {
   80                     free(mnts[i]);
   81                     mnts[i] = NULL;
   82                     continue;
   83                 }
   84                 if ((ret < 0) && (g_opt_flags & OPT_FLAGS_VERIFY)) {
   85                     if (errno != ENOSYS &&
   86                         errno != EOVERFLOW &&
   87                         errno != EACCES) {
   88                         pr_fail("%s: statfs on %s "
   89                             "failed: errno=%d (%s)\n",
   90                             args->name, mnts[i], errno,
   91                             strerror(errno));
   92                     }
   93                 }
   94 
   95                 fd = open(mnts[i], O_RDONLY | O_DIRECTORY);
   96                 if (fd < 0)
   97                     continue;
   98 
   99                 ret = fstatfs(fd, &statfs_buf);
  100                 (void)close(fd);
  101                 if ((ret < 0) && (errno == ENOENT))
  102                     continue;
  103                 if ((ret < 0) && (g_opt_flags & OPT_FLAGS_VERIFY)) {
  104                     if (errno != ENOSYS &&
  105                         errno != EOVERFLOW &&
  106                         errno != EACCES) {
  107                         pr_fail("%s: fstatfs on %s "
  108                             "failed: errno=%d (%s)\n",
  109                             args->name, mnts[i], errno,
  110                             strerror(errno));
  111                     }
  112                 }
  113             }
  114         }
  115 #endif
  116 
  117 #if defined(HAVE_USTAT)
  118         {
  119             int i;
  120 
  121             check_do_run();
  122 
  123             for (i = 0; i < n_mounts; i++) {
  124                 struct stat sbuf;
  125                 struct ustat ubuf;
  126                 int ret;
  127 
  128                 ret = stat(mnts[i], &sbuf);
  129                 if (ret < 0)
  130                     continue;
  131 
  132                 ret = ustat(sbuf.st_dev, &ubuf);
  133                 if ((ret < 0) && (g_opt_flags & OPT_FLAGS_VERIFY)) {
  134                     if (errno != EINVAL &&
  135                         errno != ENOSYS) {
  136                         pr_fail("%s: ustat on %s "
  137                             "failed: errno=%d (%s)\n",
  138                             args->name, mnts[i], errno,
  139                             strerror(errno));
  140                     }
  141                 }
  142             }
  143         }
  144 #endif
  145         check_do_run();
  146 
  147 #if defined(HAVE_SYS_STATVFS_H)
  148         {
  149             int i;
  150 
  151             struct statvfs statvfs_buf;
  152             /* POSIX.1-2001 statfs variant */
  153             for (i = 0; i < n_mounts; i++) {
  154                 int ret;
  155 
  156                 check_do_run();
  157 
  158                 if (!mnts[i])
  159                     continue;
  160 
  161                 ret = statvfs(mnts[i], &statvfs_buf);
  162                 if ((ret < 0) && (g_opt_flags & OPT_FLAGS_VERIFY)) {
  163                     if (errno != ENOSYS &&
  164                         errno != EOVERFLOW &&
  165                         errno != EACCES) {
  166                         pr_fail("%s: statvfs on %s "
  167                             "failed: errno=%d (%s)\n",
  168                             args->name, mnts[i], errno,
  169                             strerror(errno));
  170                     }
  171                 }
  172             }
  173         }
  174 #endif
  175 
  176         check_do_run();
  177         clk = times(&tms_buf);
  178         if ((clk == (clock_t)-1) && (g_opt_flags & OPT_FLAGS_VERIFY)) {
  179              pr_fail_err("times");
  180         }
  181         inc_counter(args);
  182     } while (keep_stressing());
  183 
  184     mount_free(mnts, n_mounts);
  185 
  186     return EXIT_SUCCESS;
  187 }
  188 
  189 stressor_info_t stress_sysinfo_info = {
  190     .stressor = stress_sysinfo,
  191     .class = CLASS_OS
  192 };