libstorage-ng
Disk.h
1 /*
2  * Copyright (c) [2014-2015] Novell, Inc.
3  * Copyright (c) [2016-2020] 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 
45  std::string get_transport_name(Transport transport);
46 
47 
53  enum class ZoneModel {
54  NONE, HOST_AWARE, HOST_MANAGED
55  };
56 
57 
61  std::string get_zone_model_name(ZoneModel zone_model);
62 
63 
65  class Disk : public Partitionable
66  {
67  public:
68 
69  static Disk* create(Devicegraph* devicegraph, const std::string& name);
70  static Disk* create(Devicegraph* devicegraph, const std::string& name,
71  const Region& region);
72  static Disk* create(Devicegraph* devicegraph, const std::string& name,
73  unsigned long long size);
74 
75  static Disk* load(Devicegraph* devicegraph, const xmlNode* node);
76 
80  static std::vector<Disk*> get_all(Devicegraph* devicegraph);
81 
85  static std::vector<const Disk*> get_all(const Devicegraph* devicegraph);
86 
87  bool is_rotational() const;
88 
92  Transport get_transport() const;
93 
97  ZoneModel get_zone_model() const;
98 
102  bool is_nvme() const;
103 
110  static Disk* find_by_name(Devicegraph* devicegraph, const std::string& name);
111 
115  static const Disk* find_by_name(const Devicegraph* devicegraph, const std::string& name);
116 
117  public:
118 
119  class Impl;
120 
121  Impl& get_impl();
122  const Impl& get_impl() const;
123 
124  virtual Disk* clone() const override;
125 
126  protected:
127 
128  Disk(Impl* impl);
129 
130  };
131 
132 
138  bool is_disk(const Device* device);
139 
146  Disk* to_disk(Device* device);
147 
151  const Disk* to_disk(const Device* device);
152 
153 }
154 
155 #endif
A physical disk device.
Definition: Disk.h:65
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:73
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 master container of the libstorage.
Definition: Devicegraph.h:153
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 of storage devices, and a vertex in the Devicegraph.
Definition: Device.h:75
Definition: Partitionable.h:39
Transport
Data Transport Layer.
Definition: Disk.h:37
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:37
ZoneModel
Zone model as read from /sys.
Definition: Disk.h:53