+/*
+ * XXX Should not belong to here
+ */
+static int flush_cred_ioctl(char *mp)
+{
+ int fd, rc;
+
+ fd = open(mp, O_RDONLY);
+ if (fd == -1) {
+ fprintf(stderr, "flush_cred_ioctl: error open %s: %s\n",
+ mp, strerror(errno));
+ return -1;
+ }
+
+ rc = ioctl(fd, LL_IOC_FLUSH_CRED);
+ if (rc == -1) {
+ fprintf(stderr, "flush_cred_ioctl: error ioctl %s: %s\n",
+ mp, strerror(errno));
+ }
+
+ close(fd);
+ return rc;
+}
+
+static int jt_flush_cred(int argc, char **argv)
+{
+ FILE *proc;
+ char procline[PATH_MAX], *line;
+ int i, rc = 0;
+
+ /* no args means search all lustre mountpoints */
+ if (argc < 2) {
+ proc = fopen("/proc/mounts", "r");
+ if (!proc) {
+ fprintf(stderr, "%s: can't open /proc/mounts\n",
+ jt_cmdname(argv[0]));
+ return -1;
+ }
+
+ while ((line = fgets(procline, PATH_MAX, proc)) != NULL) {
+ char dev[PATH_MAX];
+ char mp[PATH_MAX];
+ char fs[PATH_MAX];
+
+ if (sscanf(line, "%s %s %s", dev, mp, fs) != 3) {
+ fprintf(stderr, "%s: unexpected format in "
+ "/proc/mounts\n",
+ jt_cmdname(argv[0]));
+ return -1;
+ }
+
+ if (strcmp(fs, "lustre") &&
+ strcmp(fs, "lustre_lite"))
+ continue;
+
+ if (flush_cred_ioctl(mp))
+ rc = -1;
+ }
+ } else {
+ /* follow the exact flush sequence as supplied */
+ for (i = 1; i < argc; i++) {
+ if (flush_cred_ioctl(argv[i]))
+ rc = -1;
+ }
+ }
+
+ return rc;
+}
+