21
21
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22
22
* Boston, MA 021110-1307, USA.
24
* This code is a port of e2fsprogs/lib/ext2fs/dir_iterate.c
25
* Copyright (C) 1993, 1994, 1994, 1995, 1996, 1997 Theodore Ts'o.
27
26
#define _XOPEN_SOURCE 600 /* Triggers XOPEN2K in features.h */
28
27
#define _LARGEFILE64_SOURCE
228
227
/* 0 = eof, > 0 = success, < 0 = error */
229
static int dump_version_one(FILE *file, FILE *out, int lvbs)
228
static int dump_version_two(FILE *file, FILE *out)
230
unsigned long long num_prmode, num_exmode;
231
unsigned int num_prmode_failed, num_exmode_failed;
232
unsigned long long total_prmode, total_exmode;
233
unsigned int max_prmode, max_exmode, num_refresh;
236
#define NSEC_PER_USEC 1000
238
ret = fscanf(file, "%llu\t"
261
fprintf(out, "PR > Gets: %llu Fails: %u Waits (usec) Total: %llu "
263
num_prmode, num_prmode_failed, total_prmode/NSEC_PER_USEC,
264
max_prmode/NSEC_PER_USEC);
265
fprintf(out, "EX > Gets: %llu Fails: %u Waits (usec) Total: %llu "
267
num_exmode, num_exmode_failed, total_exmode/NSEC_PER_USEC,
268
max_exmode/NSEC_PER_USEC);
269
fprintf(out, "Disk Refreshes: %u\n", num_refresh);
276
/* 0 = eof, > 0 = success, < 0 = error */
277
static int dump_version_one(FILE *file, FILE *out, int lvbs, int only_busy,
278
struct list_head *locklist, int *skipped,
279
unsigned int version)
231
281
char id[OCFS2_LOCK_ID_MAX_LEN + 1];
232
282
char lvb[DLM_LVB_LEN];
329
ret = dump_version_one(file, out, lvbs);
398
ret = dump_version_one(file, out, lvbs, only_busy, locklist, &skipped, version);
403
if (version == CURRENT_PROTO) {
404
ret = dump_version_two(file, out);
333
412
/* Read to the end of the record here. Any new fields tagged
334
413
* onto the current format will be silently ignored. */
335
414
ret = !end_line(file);
340
#define DEBUGFS_MAGIC 0x64626720
341
static errcode_t try_debugfs_path(const char *path)
344
struct stat64 stat_buf;
345
struct statfs64 statfs_buf;
347
ret = stat64(path, &stat_buf);
348
if (ret || !S_ISDIR(stat_buf.st_mode))
349
return O2CB_ET_SERVICE_UNAVAILABLE;
350
ret = statfs64(path, &statfs_buf);
351
if (ret || (statfs_buf.f_type != DEBUGFS_MAGIC))
352
return O2CB_ET_SERVICE_UNAVAILABLE;
357
#define LOCKING_STATE_FORMAT_PATH "%s/ocfs2/%s/locking_state"
358
static errcode_t open_locking_state(const char *debugfs_path,
359
const char *uuid_str,
365
ret = snprintf(path, PATH_MAX - 1, LOCKING_STATE_FORMAT_PATH,
366
debugfs_path, uuid_str);
367
if ((ret <= 0) || (ret == (PATH_MAX - 1)))
368
return O2CB_ET_INTERNAL_FAILURE;
370
*state_file = fopen(path, "r");
374
ret = O2CB_ET_INTERNAL_FAILURE;
380
ret = O2CB_ET_SERVICE_UNAVAILABLE;
386
ret = O2CB_ET_PERMISSION_DENIED;
397
#define SYSFS_BASE "/sys/kernel/"
398
#define DEBUGFS_PATH SYSFS_BASE "debug"
399
#define DEBUGFS_ALTERNATE_PATH "/debug"
401
void dump_fs_locks(char *uuid_str, FILE *out, int dump_lvbs)
405
const char *debugfs_path = DEBUGFS_PATH;
406
struct stat64 stat_buf;
419
void dump_fs_locks(char *uuid_str, FILE *out, char *path, int dump_lvbs,
420
int only_busy, struct list_head *locklist)
423
char debugfs_path[PATH_MAX];
409
err = stat64(SYSFS_BASE, &stat_buf);
411
debugfs_path = DEBUGFS_ALTERNATE_PATH;
413
ret = try_debugfs_path(debugfs_path);
415
fprintf(stderr, "Could not locate debugfs file system. "
416
"Perhaps it is not mounted?\n");
420
ret = open_locking_state(debugfs_path, uuid_str, &file);
422
fprintf(stderr, "Could not open debug state for \"%s\".\n"
423
"Perhaps that OCFS2 file system is not mounted?\n",
428
while (dump_one_lockres(file, out, dump_lvbs))
428
ret = get_debugfs_path(debugfs_path, sizeof(debugfs_path));
430
fprintf(stderr, "Could not locate debugfs file system. "
431
"Perhaps it is not mounted?\n");
435
ret = open_debugfs_file(debugfs_path, "ocfs2", uuid_str,
436
"locking_state", &file);
438
fprintf(stderr, "Could not open debug state for "
439
"\"%s\".\nPerhaps that OCFS2 file system is "
440
"not mounted?\n", uuid_str);
444
file = fopen(path, "r");
446
fprintf(stderr, "Could not open file at \"%s\"\n",
452
show_select = !list_empty(locklist);
454
while (dump_one_lockres(file, out, dump_lvbs, only_busy, locklist)) {
455
if (show_select && list_empty(locklist))