"Fossies" - the Fresh Open Source Software Archive

Member "stress-ng-0.09.56/stress-iosync.c" (15 Mar 2019, 2097 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-iosync.c" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 0.09.52_vs_0.09.54.

    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 MAX_MNTS    (256)
   28 
   29 /*
   30  *  stress on sync()
   31  *  stress system by IO sync calls
   32  */
   33 static int stress_io(const args_t *args)
   34 {
   35 #if defined(HAVE_SYNCFS)
   36     int i, fd, n_mnts;
   37     char *mnts[MAX_MNTS];
   38     int  fds[MAX_MNTS];
   39 
   40     n_mnts = mount_get(mnts, MAX_MNTS);
   41     for (i = 0; i < n_mnts; i++)
   42         fds[i] = openat(AT_FDCWD, mnts[i], O_RDONLY | O_NONBLOCK | O_DIRECTORY);
   43 
   44     fd = openat(AT_FDCWD, ".", O_RDONLY | O_NONBLOCK | O_DIRECTORY);
   45 #endif
   46 
   47     do {
   48         (void)sync();
   49 #if defined(HAVE_SYNCFS)
   50         if ((fd != -1) && (syncfs(fd) < 0))
   51             pr_fail_err("syncfs");
   52 
   53         /* try to sync on all the mount points */
   54         for (i = 0; i < n_mnts; i++)
   55             if (fds[i] != -1)
   56                 (void)syncfs(fds[i]);
   57 #endif
   58         inc_counter(args);
   59     } while (keep_stressing());
   60 
   61 #if defined(HAVE_SYNCFS)
   62     if (fd != -1)
   63         (void)close(fd);
   64 
   65     for (i = 0; i < n_mnts; i++)
   66         if (fds[i] != -1)
   67             (void)close(fds[i]);
   68 
   69     mount_free(mnts, n_mnts);
   70 #endif
   71 
   72     return EXIT_SUCCESS;
   73 }
   74 
   75 stressor_info_t stress_io_info = {
   76     .stressor = stress_io,
   77     .class = CLASS_FILESYSTEM | CLASS_OS
   78 };