Blame SOURCES/0070-Add-support-for-RAM-drives.patch

0cb0b9
From eb927155680f75e570dc7375514e344a936a3fb5 Mon Sep 17 00:00:00 2001
0cb0b9
From: "Brian C. Lane" <bcl@redhat.com>
0cb0b9
Date: Mon, 1 May 2017 17:05:01 -0700
0cb0b9
Subject: [PATCH 70/75] Add support for RAM drives
0cb0b9
0cb0b9
Recognize RAM drives, so "parted -s /dev/ram0 p" now prints
0cb0b9
"RAM Drive (brd)" instead of "Model: Unknown (unknown)".
0cb0b9
0cb0b9
In order for a device to be recognized as RAM drive, it has to
0cb0b9
have major number 1. Also the BLKFLSBUF ioctl shouldn't be used
0cb0b9
on RAM drives as it is used to zero the device.
0cb0b9
0cb0b9
* NEWS: Mention the change
0cb0b9
* include/parted/device.h.in(PedDeviceType): Add PED_DEVICE_RAM.
0cb0b9
* libparted/arch/linux.c(RAM_MAJOR): New define.
0cb0b9
* libparted/arch/linux.c(_device_probe_type): Recognize RAM drives.
0cb0b9
* libparted/arch/linux.c(linux_new): Handle RAM drives.
0cb0b9
* libparted/arch/linux.c(_flush_cache): Skip RAM drives.
0cb0b9
* parted/parted.c(do_print): Add "brd" to list of transports.
0cb0b9
0cb0b9
Signed-off-by: Sebastian Parschauer <sparschauer@suse.de>
0cb0b9
---
0cb0b9
 include/parted/device.in.h |  3 ++-
0cb0b9
 libparted/arch/linux.c     | 12 ++++++++++--
0cb0b9
 parted/parted.c            |  2 +-
0cb0b9
 3 files changed, 13 insertions(+), 4 deletions(-)
0cb0b9
0cb0b9
diff --git a/include/parted/device.in.h b/include/parted/device.in.h
0cb0b9
index d38db44..1b6e7b8 100644
0cb0b9
--- a/include/parted/device.in.h
0cb0b9
+++ b/include/parted/device.in.h
0cb0b9
@@ -50,7 +50,8 @@ typedef enum {
0cb0b9
         PED_DEVICE_AOE          = 16,
0cb0b9
         PED_DEVICE_MD           = 17,
0cb0b9
         PED_DEVICE_LOOP         = 18,
0cb0b9
-        PED_DEVICE_NVME         = 19
0cb0b9
+        PED_DEVICE_NVME         = 19,
0cb0b9
+        PED_DEVICE_RAM          = 20
0cb0b9
 } PedDeviceType;
0cb0b9
 
0cb0b9
 typedef struct _PedDevice PedDevice;
0cb0b9
diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
0cb0b9
index 2058697..c2fdab0 100644
0cb0b9
--- a/libparted/arch/linux.c
0cb0b9
+++ b/libparted/arch/linux.c
0cb0b9
@@ -279,6 +279,7 @@ struct blkdev_ioctl_param {
0cb0b9
 #define LOOP_MAJOR              7
0cb0b9
 #define MD_MAJOR                9
0cb0b9
 #define BLKEXT_MAJOR            259
0cb0b9
+#define RAM_MAJOR               1
0cb0b9
 
0cb0b9
 #define SCSI_BLK_MAJOR(M) (                                             \
0cb0b9
                 (M) == SCSI_DISK0_MAJOR                                 \
0cb0b9
@@ -701,6 +702,8 @@ _device_probe_type (PedDevice* dev)
0cb0b9
                 dev->type = PED_DEVICE_MD;
0cb0b9
         } else if (_is_blkext_major(dev_major) && dev->path && strstr(dev->path, "nvme")) {
0cb0b9
                 dev->type = PED_DEVICE_NVME;
0cb0b9
+        } else if (dev_major == RAM_MAJOR) {
0cb0b9
+                dev->type = PED_DEVICE_RAM;
0cb0b9
         } else {
0cb0b9
                 dev->type = PED_DEVICE_UNKNOWN;
0cb0b9
         }
0cb0b9
@@ -1547,6 +1550,11 @@ linux_new (const char* path)
0cb0b9
                         goto error_free_arch_specific;
0cb0b9
                 break;
0cb0b9
 
0cb0b9
+        case PED_DEVICE_RAM:
0cb0b9
+                if (!init_generic (dev, _("RAM Drive")))
0cb0b9
+                        goto error_free_arch_specific;
0cb0b9
+                break;
0cb0b9
+
0cb0b9
         default:
0cb0b9
                 ped_exception_throw (PED_EXCEPTION_NO_FEATURE,
0cb0b9
                                 PED_EXCEPTION_CANCEL,
0cb0b9
@@ -1619,9 +1627,9 @@ _flush_cache (PedDevice* dev)
0cb0b9
 {
0cb0b9
         LinuxSpecific*  arch_specific = LINUX_SPECIFIC (dev);
0cb0b9
         int             i;
0cb0b9
-	int             lpn = _device_get_partition_range(dev);
0cb0b9
+        int             lpn = _device_get_partition_range(dev);
0cb0b9
 
0cb0b9
-        if (dev->read_only)
0cb0b9
+        if (dev->read_only || dev->type == PED_DEVICE_RAM)
0cb0b9
                 return;
0cb0b9
         dev->dirty = 0;
0cb0b9
 
0cb0b9
diff --git a/parted/parted.c b/parted/parted.c
0cb0b9
index f767bec..a7fcd3b 100644
0cb0b9
--- a/parted/parted.c
0cb0b9
+++ b/parted/parted.c
0cb0b9
@@ -979,7 +979,7 @@ _print_disk_info (const PedDevice *dev, const PedDisk *diskp)
0cb0b9
                                          "cpqarray", "file", "ataraid", "i2o",
0cb0b9
                                          "ubd", "dasd", "viodasd", "sx8", "dm",
0cb0b9
                                          "xvd", "sd/mmc", "virtblk", "aoe",
0cb0b9
-                                         "md", "loopback", "nvme"};
0cb0b9
+                                         "md", "loopback", "nvme", "brd"};
0cb0b9
 
0cb0b9
         char* start = ped_unit_format (dev, 0);
0cb0b9
         PedUnit default_unit = ped_unit_get_default ();
0cb0b9
-- 
0cb0b9
2.9.3
0cb0b9