* Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
*
- * Copyright (c) 2011, 2012, Intel Corporation.
+ * Copyright (c) 2012, 2015, Intel Corporation.
*/
/*
* This file is part of Lustre, http://www.lustre.org/
* Lustre is a trademark of Sun Microsystems, Inc.
*/
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <sys/time.h>
+#include <sys/mman.h>
+#include <limits.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
-#include <sys/mman.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
#include <fcntl.h>
-#include <netinet/in.h>
-#include <sys/socket.h>
-#include <netdb.h>
+#include <getopt.h>
#include <string.h>
-#include <sys/wait.h>
-#include <sys/time.h>
+#include <errno.h>
+
+#include <libcfs/util/param.h>
char *dir = NULL, *dir2 = NULL;
long page_size;
return rc;
}
-static int cancel_lru_locks(char *prefix)
+static int cancel_lru_locks(char *filter)
{
- char cmd[256], line[1024];
- FILE *file;
- pid_t child;
- int len = 1024, rc = 0;
-
- child = fork();
- if (child < 0)
- return -errno;
- else if (child) {
- int status;
- rc = waitpid(child, &status, WNOHANG);
- if (rc == child)
- rc = 0;
- return rc;
- }
-
- if (prefix)
- sprintf(cmd,
- "ls /proc/fs/lustre/ldlm/namespaces/*-%s-*/lru_size",
- prefix);
- else
- sprintf(cmd, "ls /proc/fs/lustre/ldlm/namespaces/*/lru_size");
-
- file = popen(cmd, "r");
- if (file == NULL) {
- perror("popen()");
- return -errno;
- }
-
- while (fgets(line, len, file)) {
- FILE *f;
-
- if (!strlen(line))
- continue;
- /* trim newline character */
- *(line + strlen(line) - 1) = '\0';
- f = fopen(line, "w");
- if (f == NULL) {
- perror("fopen()");
- rc = -errno;
- break;
- }
- rc = fwrite("clear", strlen("clear") + 1, 1, f);
- if (rc < 1) {
- perror("fwrite()");
- rc = -errno;
- fclose(f);
- break;
- }
- fclose(f);
- }
-
- pclose(file);
- _exit(rc);
+ glob_t paths;
+ pid_t child;
+ int rc, i;
+
+ child = fork();
+ if (child < 0)
+ return -errno;
+ else if (child) {
+ int status;
+
+ rc = waitpid(child, &status, WNOHANG);
+ if (rc == child)
+ rc = 0;
+ return rc;
+ }
+
+ if (filter != NULL)
+ rc = cfs_get_param_paths(&paths,
+ "ldlm/namespaces/*-%s-*/lru_size",
+ filter);
+ else
+ rc = cfs_get_param_paths(&paths,
+ "ldlm/namespaces/*/lru_size");
+ if (rc != 0)
+ return -EINVAL;
+
+ for (i = 0; i < paths.gl_pathc; i++) {
+ FILE *f = fopen(paths.gl_pathv[i], "r");
+ if (f == NULL) {
+ rc = -errno;
+ fprintf(stderr, "cannot open '%s': %s\n",
+ paths.gl_pathv[i], strerror(errno));
+ break;
+ }
+
+ rc = fwrite("clear", strlen("clear") + 1, 1, f);
+ if (rc < 1) {
+ rc = -errno;
+ fprintf(stderr, "fwrite failed for '%s': %s\n",
+ paths.gl_pathv[i], strerror(errno));
+ fclose(f);
+ break;
+ }
+ fclose(f);
+ }
+
+ cfs_free_param_data(&paths);
+ _exit(rc);
}
/* don't dead lock while read/write file to/from the buffer which