Commit bc3d518f authored by Raine Makelainen's avatar Raine Makelainen

[nemo-storage] Make block devices without partition/partitiontable visible in model. Fixes JB#42943

This commit adds signleton block devices container that is the main
interface that monitor uses for operating block devices. The block devices
emits a signal (newBlock) when it sees an acceptable new block device and throws
away the ones that cannot / should not be shown in the model.

When block device container sees a block device that could be a container
for a partition, it'll wait for 3000ms milliseconds before accepting the
block. If partition appears during this inverval, then waiting is cancel.
parent e1d9073b
......@@ -31,6 +31,7 @@
#include "partitionmanager_p.h"
#include "udisks2monitor_p.h"
#include "udisks2blockdevices_p.h"
#include "logging_p.h"
#include <QFile>
......@@ -340,7 +341,7 @@ QString PartitionManagerPrivate::objectPath(const QString &devicePath) const
{
QString deviceName = devicePath.section(QChar('/'), 2);
if (externalMedia.match(deviceName).hasMatch()) {
return m_udisksMonitor->instance()->objectPath(devicePath);
return UDisks2::BlockDevices::instance()->objectPath(devicePath);
} else {
qCWarning(lcMemoryCardLog) << "Object path existing only for external memory cards:" << devicePath;
return QString();
......
......@@ -39,6 +39,7 @@ SOURCES += \
locationsettings.cpp \
timezoneinfo.cpp \
udisks2block.cpp \
udisks2blockdevices.cpp \
udisks2job.cpp \
udisks2monitor.cpp
......@@ -78,6 +79,7 @@ HEADERS += \
partition_p.h \
partitionmanager_p.h \
udisks2block_p.h \
udisks2blockdevices_p.h \
udisks2job_p.h \
udisks2monitor_p.h
......
This diff is collapsed.
......@@ -35,6 +35,7 @@
#include <QObject>
#include <QVariantMap>
#include <QDBusConnection>
#include <QPointer>
#include "udisks2defines.h"
......@@ -42,14 +43,13 @@ class QDBusPendingCallWatcher;
namespace UDisks2 {
class Block : public QObject
{
Q_OBJECT
Q_PROPERTY(QString connectionBus READ connectionBus NOTIFY updated)
public:
Block(const QString &path, const UDisks2::InterfacePropertyMap &interfacePropertyMap, QObject *parent = nullptr);
virtual ~Block();
QString path() const;
......@@ -58,6 +58,10 @@ public:
QString preferredDevice() const;
QString drive() const;
QString connectionBus() const;
QString partitionTable() const;
bool isPartition() const;
bool isPartitionTable() const;
qint64 deviceNumber() const;
QString id() const;
......@@ -99,34 +103,38 @@ public:
static QString cryptoBackingDevicePath(const QString &objectPath);
void addInterface(const QString &interface, QVariantMap propertyMap);
void removeInterface(const QString &interface);
void morph(const Block& other);
signals:
void completed();
void completed(QPrivateSignal);
void updated();
void formatted();
void mountPathChanged();
private slots:
void updateProperties(const QDBusMessage &message);
void complete();
private:
Block(const QString &path, const UDisks2::InterfacePropertyMap &interfacePropertyMap, QObject *parent = nullptr);
Block& operator=(const Block& other);
bool setEncrypted(bool encrypted);
bool setMountable(bool mountable);
void addInterface(const QString &interface, QVariantMap propertyMap);
void removeInterface(const QString &interface);
int interfaceCount() const;
bool hasInterface(const QString &interface) const;
bool isCompleted() const;
void updateMountPoint(const QVariant &mountPoints);
void complete();
void updateFileSystemInterface(const QVariant &mountPoints);
bool clearFormattingState();
void getFileSystemInterface();
void getEncryptedInterface();
void getDriveProperties();
void getProperties(const QString &path, const QString &interface,
QPointer<QDBusPendingCallWatcher> &watcherPointer,
std::function<void (const QVariantMap &)> success);
void rescan(const QString &dbusObjectPath);
......@@ -141,10 +149,14 @@ private:
bool m_formatting;
bool m_locking;
QDBusPendingCallWatcher *m_pendingFileSystem;
QDBusPendingCallWatcher *m_pendingBlock;
QDBusPendingCallWatcher *m_pendingEncrypted;
QDBusPendingCallWatcher *m_pendingDrive;
QPointer<QDBusPendingCallWatcher> m_pendingFileSystem;
QPointer<QDBusPendingCallWatcher> m_pendingBlock;
QPointer<QDBusPendingCallWatcher> m_pendingEncrypted;
QPointer<QDBusPendingCallWatcher> m_pendingDrive;
QPointer<QDBusPendingCallWatcher> m_pendingPartition;
QPointer<QDBusPendingCallWatcher> m_pendingPartitionTable;
friend class BlockDevices;
};
}
......
This diff is collapsed.
/*
* Copyright (C) 2018 Jolla Ltd. <raine.makelainen@jolla.com>
*
* You may use this file under the terms of the BSD license as follows:
*
* "Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Nemo Mobile nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
*/
#ifndef UDISKS2_BLOCK_DEVICES_H
#define UDISKS2_BLOCK_DEVICES_H
#include <QMap>
#include "udisks2block_p.h"
class QTimerEvent;
namespace UDisks2 {
class BlockDevices : public QObject
{
Q_OBJECT
public:
static BlockDevices* instance();
virtual ~BlockDevices() override;
bool contains(const QString &dbusObjectPath) const;
void remove(const QString &dbusObjectPath);
Block *device(const QString &dbusObjectPath) const;
Block *replace(const QString &dbusObjectPath, Block *block);
void insert(const QString &dbusObjectPath, Block *block);
Block *find(std::function<bool (const Block *block)> condition);
Block *find(const QString &devicePath);
QString objectPath(const QString &devicePath) const;
QStringList devicePaths(const QStringList &dbusObjectPaths) const;
bool createBlockDevice(const QString &dbusObjectPath, const InterfacePropertyMap &interfacePropertyMap);
void lock(const QString &dbusObjectPath);
void waitPartition(Block *block);
void clearPartitionWait(const QString &dbusObjectPath, bool destroyBlock);
void removeInterfaces(const QString &dbusObjectPath, const QStringList &interfaces);
void dumpBlocks() const;
static bool isExternal(const QString &dbusObjectPath);
signals:
void newBlock(Block *block);
private slots:
void blockCompleted();
private:
struct PartitionWaiter {
PartitionWaiter(int timer, Block *block);
~PartitionWaiter();
int timer;
Block *block;
};
BlockDevices(QObject *parent = nullptr);
Block *doCreateBlockDevice(const QString &dbusObjectPath, const InterfacePropertyMap &interfacePropertyMap);
void updateFormattingState(Block *block);
void complete(Block *block, bool forceAccept = false);
void timerEvent(QTimerEvent *e) override;
QMap<QString, Block *> m_blockDevices;
QMap<QString, PartitionWaiter*> m_partitionWaits;
static BlockDevices *sharedInstance;
};
}
#endif
......@@ -54,13 +54,14 @@ Q_DECLARE_METATYPE(UDisks2::InterfacePropertyMap)
#define UDISKS2_MANAGER_PATH QLatin1String("/org/freedesktop/UDisks2/Manager")
// Interfaces
#define UDISKS2_MANAGER_INTERFACE QLatin1String("org.freedesktop.UDisks2.Manager")
#define UDISKS2_ENCRYPTED_INTERFACE QLatin1String("org.freedesktop.UDisks2.Encrypted")
#define UDISKS2_DRIVE_INTERFACE QLatin1String("org.freedesktop.UDisks2.Drive")
#define UDISKS2_BLOCK_INTERFACE QLatin1String("org.freedesktop.UDisks2.Block")
#define UDISKS2_FILESYSTEM_INTERFACE QLatin1String("org.freedesktop.UDisks2.Filesystem")
#define UDISKS2_PARTITION_INTERFACE QLatin1String("org.freedesktop.UDisks2.Partition")
#define UDISKS2_JOB_INTERFACE QLatin1String("org.freedesktop.UDisks2.Job")
#define UDISKS2_MANAGER_INTERFACE QLatin1String("org.freedesktop.UDisks2.Manager")
#define UDISKS2_ENCRYPTED_INTERFACE QLatin1String("org.freedesktop.UDisks2.Encrypted")
#define UDISKS2_DRIVE_INTERFACE QLatin1String("org.freedesktop.UDisks2.Drive")
#define UDISKS2_BLOCK_INTERFACE QLatin1String("org.freedesktop.UDisks2.Block")
#define UDISKS2_FILESYSTEM_INTERFACE QLatin1String("org.freedesktop.UDisks2.Filesystem")
#define UDISKS2_PARTITION_INTERFACE QLatin1String("org.freedesktop.UDisks2.Partition")
#define UDISKS2_PARTITION_TABLE_INTERFACE QLatin1String("org.freedesktop.UDisks2.PartitionTable")
#define UDISKS2_JOB_INTERFACE QLatin1String("org.freedesktop.UDisks2.Job")
// Jobs
#define UDISKS2_JOB_OP_ENC_LOCK QLatin1String("encrypted-lock")
......
......@@ -137,17 +137,16 @@ UDisks2::Job::Operation UDisks2::Job::operation() const
}
}
void UDisks2::Job::dumpInfo() const
{
qCInfo(lcMemoryCardLog) << "Job" << path() << ((status() == Added) ? "added" : "completed");
for (const QString &key : m_data.keys()) {
qCInfo(lcMemoryCardLog) << "- " << qPrintable(key) << value(key);
}
}
void UDisks2::Job::updateCompleted(bool success, const QString &message)
{
complete(success);
m_message = message;
QDBusConnection systemBus = QDBusConnection::systemBus();
systemBus.disconnect(
UDISKS2_SERVICE,
m_path,
UDISKS2_JOB_INTERFACE,
QStringLiteral("Completed"),
this,
SLOT(updateJobStatus(bool, QString)));
complete(success);
}
......@@ -76,6 +76,8 @@ public:
Status status() const;
Operation operation() const;
void dumpInfo() const;
signals:
void completed(bool success);
......
This diff is collapsed.
......@@ -50,6 +50,7 @@ static const QRegularExpression deviceRoot(QStringLiteral("^mmcblk\\d+$"));
namespace UDisks2 {
class Block;
class BlockDevices;
class Job;
struct Operation
......@@ -86,8 +87,6 @@ public:
void format(const QString &devicePath, const QString &filesystemType, const QVariantMap &arguments);
QString objectPath(const QString &devicePath) const;
signals:
void status(const QString &devicePath, Partition::Status);
void errorMessage(const QString &objectPath, const QString &errorName);
......@@ -101,33 +100,30 @@ private slots:
void interfacesAdded(const QDBusObjectPath &objectPath, const UDisks2::InterfacePropertyMap &interfaces);
void interfacesRemoved(const QDBusObjectPath &objectPath, const QStringList &interfaces);
void doFormat(const QString &devicePath, const QString &dbusObjectPath, const QString &filesystemType, const QVariantMap &arguments);
void handleNewBlock(UDisks2::Block *block);
private:
void setPartitionProperties(QExplicitlySharedDataPointer<PartitionPrivate> &partition, const Block *blockDevice);
void updatePartitionProperties(const Block *blockDevice);
void updatePartitionStatus(const Job *job, bool success);
bool externalBlockDevice(const QString &objectPathStr) const;
void startLuksOperation(const QString &devicePath, const QString &dbusMethod, const QString &dbusObjectPath, const QVariantList &arguments);
void startMountOperation(const QString &devicePath, const QString &dbusMethod, const QString &dbusObjectPath, const QVariantList &arguments);
void lookupPartitions(PartitionManagerPrivate::Partitions &affectedPartitions, const QStringList &objects);
void createPartition(const Block *block);
Block *createBlockDevice(const QString &dbusObjectPath, const UDisks2::InterfacePropertyMap &interfacePropertyMap);
void getBlockDevices();
Block *findBlock(const QString &devicePath) const;
void updateFormattingState(UDisks2::Block *block);
void connectSignals(UDisks2::Block *block);
private:
static Monitor *sharedInstance;
QExplicitlySharedDataPointer<PartitionManagerPrivate> m_manager;
QMap<QString, Job *> m_jobsToWait;
QMap<QString, Block *> m_blockDevices;
QQueue<Operation> m_operationQueue;
BlockDevices *m_blockDevices;
};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment