libstorage-ng
Disk.h
1 /*
2  * Copyright (c) [2014-2015] Novell, Inc.
3  * Copyright (c) [2016-2021] SUSE LLC
4  *
5  * All Rights Reserved.
6  *
7  * This program is free software; you can redistribute it and/or modify it
8  * under the terms of version 2 of the GNU General Public License as published
9  * by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, contact Novell, Inc.
18  *
19  * To contact Novell about this file by physical or electronic mail, you may
20  * find current contact information at www.novell.com.
21  */
22 
23 
24 #ifndef STORAGE_DISK_H
25 #define STORAGE_DISK_H
26 
27 
28 #include "storage/Devices/Partitionable.h"
29 
30 
31 namespace storage
32 {
33 
37  enum class Transport {
38  UNKNOWN, SBP, ATA, FC, ISCSI, SAS, SATA, SPI, USB, FCOE
39  };
40 
41 
47  std::string get_transport_name(Transport transport);
48 
49 
56  enum class ZoneModel {
57  NONE, HOST_AWARE, HOST_MANAGED
58  };
59 
60 
66  std::string get_zone_model_name(ZoneModel zone_model);
67 
68 
72  class Disk : public Partitionable
73  {
74  public:
75 
82  static Disk* create(Devicegraph* devicegraph, const std::string& name);
83 
87  static Disk* create(Devicegraph* devicegraph, const std::string& name,
88  const Region& region);
89 
93  static Disk* create(Devicegraph* devicegraph, const std::string& name,
94  unsigned long long size);
95 
96  static Disk* load(Devicegraph* devicegraph, const xmlNode* node);
97 
101  static std::vector<Disk*> get_all(Devicegraph* devicegraph);
102 
106  static std::vector<const Disk*> get_all(const Devicegraph* devicegraph);
107 
113  bool is_rotational() const;
114 
119  bool is_dax() const;
120 
124  Transport get_transport() const;
125 
131  ZoneModel get_zone_model() const;
132 
136  bool is_pmem() const;
137 
141  bool is_nvme() const;
142 
146  const std::string& get_image_filename() const;
147 
152  void set_image_filename(const std::string& image_filename);
153 
160  static Disk* find_by_name(Devicegraph* devicegraph, const std::string& name);
161 
165  static const Disk* find_by_name(const Devicegraph* devicegraph, const std::string& name);
166 
167  public:
168 
169  class Impl;
170 
171  Impl& get_impl();
172  const Impl& get_impl() const;
173 
174  virtual Disk* clone() const override;
175 
176  protected:
177 
178  Disk(Impl* impl);
179 
180  };
181 
182 
188  bool is_disk(const Device* device);
189 
196  Disk* to_disk(Device* device);
197 
201  const Disk* to_disk(const Device* device);
202 
203 }
204 
205 #endif
A physical disk device.
Definition: Disk.h:72
const std::string & get_image_filename() const
Get the filename for the underlying image.
void set_image_filename(const std::string &image_filename)
Set the filename for the underlying image.
bool is_disk(const Device *device)
Checks whether device points to a Disk.
Disk * to_disk(Device *device)
Converts pointer to Device to pointer to Disk.
A start/length pair with a block size.
Definition: Region.h:84
std::string get_transport_name(Transport transport)
Convert the Transport transport to a string.
std::string get_zone_model_name(ZoneModel zone_model)
Convert the ZoneModel zone_model to a string.
The main container of the libstorage-ng.
Definition: Devicegraph.h:169
Transport get_transport() const
Get the transport of the disk.
ZoneModel get_zone_model() const
Get the zone model of the disk.
bool is_nvme() const
Return whether the disk is an NVMe device.
An abstract base class for storage devices.
Definition: Device.h:81
Definition: Partitionable.h:39
Transport
Data Transport Layer.
Definition: Disk.h:37
bool is_rotational() const
Return whether the disk is of rotational or non-rotational type.
bool is_pmem() const
Return whether the disk is an PMEM device.
static Disk * find_by_name(Devicegraph *devicegraph, const std::string &name)
Find a Disk by its name.
static std::vector< Disk * > get_all(Devicegraph *devicegraph)
Get all Disks.
The storage namespace.
Definition: Actiongraph.h:38
static Disk * create(Devicegraph *devicegraph, const std::string &name)
Create a device of type Disk.
ZoneModel
Zone model as read from /sys.
Definition: Disk.h:56
bool is_dax() const
Return whether the disk supports Direct Access (DAX).