btrfs-progs: misc-test: use raid1 for data to enable mount with -o degraded
[platform/upstream/btrfs-progs.git] / utils.c
diff --git a/utils.c b/utils.c
index 3db8bdd..524f463 100644 (file)
--- a/utils.c
+++ b/utils.c
@@ -24,6 +24,7 @@
 #include <sys/mount.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <sys/sysinfo.h>
 #include <uuid/uuid.h>
 #include <fcntl.h>
 #include <unistd.h>
@@ -1804,7 +1805,8 @@ int is_seen_fsid(u8 *fsid, struct seen_fsid *seen_fsid_hash[])
        return 0;
 }
 
-int add_seen_fsid(u8 *fsid, struct seen_fsid *seen_fsid_hash[])
+int add_seen_fsid(u8 *fsid, struct seen_fsid *seen_fsid_hash[],
+               int fd, DIR *dirstream)
 {
        u8 hash = fsid[0];
        int slot = hash % SEEN_FSID_HASH_SIZE;
@@ -1831,6 +1833,8 @@ insert:
 
        alloc->next = NULL;
        memcpy(alloc->fsid, fsid, BTRFS_FSID_SIZE);
+       alloc->fd = fd;
+       alloc->dirstream = dirstream;
 
        if (seen)
                seen->next = alloc;
@@ -1850,6 +1854,7 @@ void free_seen_fsid(struct seen_fsid *seen_fsid_hash[])
                seen = seen_fsid_hash[slot];
                while (seen) {
                        next = seen->next;
+                       close_file_or_dir(seen->fd, seen->dirstream);
                        free(seen);
                        seen = next;
                }
@@ -2684,3 +2689,15 @@ u8 rand_u8(void)
 void btrfs_config_init(void)
 {
 }
+
+/* Returns total size of main memory in bytes, -1UL if error. */
+unsigned long total_memory(void)
+{
+        struct sysinfo si;
+
+        if (sysinfo(&si) < 0) {
+                error("can't determine memory size");
+                return -1UL;
+        }
+        return si.totalram * si.mem_unit;       /* bytes */
+}