CA-135187: Filter out restricted device_config keys

A commit fixing SCTX-1616 now causes PBD create to throw an error if given
a device_config with the SRmaster key in (internal use only).

However, if this happened to exist from a time when this was not forbidden then
pool join will fail since the slave uses the device_config from the master's
PBD record which might contain this key.

This commit filters this key out in the pool join code-path.

Signed-off-by: Si Beaumont <simon.beaumont@citrix.com>
CA-135189: Remove restricted device_config on upgrade

The SRmaster key is restricted for internal use only. There are precautions
taken against creating PBDs with such a key in the device config now but we
should purge the database of any such keys created before these measures were
in place.

Signed-off-by: Si Beaumont <simon.beaumont@citrix.com>
Start SMAPIv1 proxies listening for requests via the message switch
Fix SMAPIv1 backwards compatibility on pool slaves

The two facts:
  Only the master should list the SM plugins directly.
  When the proxies are being started up on the master, the SM database
    records haven't been created.

Imply that we should query Sm.* when running on the master, but use
the SM database records on the slave.

Signed-off-by: David Scott <dave.scott@eu.citrix.com>
All SMAPI access is now routed through the xcp-idl client code

If we have message switch enabled then it will be used, otherwise
we still use unix domain sockets.

Note the special-case handling of SR.probe.

Signed-off-by: David Scott <dave.scott@citrix.com>
storage: create per-SR unix domain sockets in storage.d/<name>

This avoids clashing with the global unix domain socket 'storage'

Signed-off-by: David Scott <dave.scott@eu.citrix.com>
message-switch: explicitly specify which xenopsd instance we want

Normally we use the 'default' one but this policy could be refined later.

Signed-off-by: David Scott <dave.scott@citrix.com>
CA-134765: Fix race condition in database layer

The read_records_where function in the database layer (used by the
get_all_records and get_all_records_where APIs) was reading the database
multiple times by calling find_refs_with_filter[1] to get the refs that matched
the query and then calling read_record[2] for each of these refs.

This violates point #2 of the  locking strategy stated at the top of the module
that read only functions must only call get_database once to ensure they
operate on a consistent snapshot.

Since [1] and [2] make get_database calls the get_all_records* functions make
n+1 calls to get_database for a table with n records. Because of this, deleting
a record during a get_all_records_where will result in a DBCache_NotFound
exception with parameter "missing row".

This commits adds internal variants of functions [1] and [2] that take
an actual instance of Database.t rather than a Db_ref.t which is a Database.t
ref ref.

Signed-off-by: Si Beaumont <simon.beaumont@citrix.com>
Merge pull request #1745 from simonjbeaumont/ca-134675

CA-134765: Fix race condition in database layer
Merge pull request #1734 from simonjbeaumont/sctx-1616

CA-135187: Filter out restricted device_config keys
Merge pull request #1736 from simonjbeaumont/ca-135189

CA-135189: Remove restricted device_config on upgrade
lspci: look in both /sbin/lspci and /usr/bin/lspci

Ideally we should use $PATH-- forkexecd should do this if asked
to execute a relative filename. In the short-term, cope with both
CentOS and Ubuntu paths.

Signed-off-by: David Scott <dave.scott@citrix.com>
Add a test for event inject

Signed-off-by: Jon Ludlam <jonathan.ludlam@citrix.com>
Fix a defect where event.from can go into a tight loop

This puts the subscription check into the inner loop
of the event.from rather than when gathering the
snapshots. This fixes a problem where xapi would go into
a tight loop when subscribed to a particular objects
events and a different object of the same class was
updated. This tight loop also wouldn't perform the
session check so logging out the session wouldn't cause
the call to return.

Signed-off-by: Jon Ludlam <jonathan.ludlam@citrix.com>
If we're not using the message switch, there can be only one xenopsd.

Signed-off-by: Jon Ludlam <jonathan.ludlam@citrix.com>
Ignore new artifacts of OUnit2 test runs

Signed-off-by: Si Beaumont <simon.beaumont@citrix.com>
Merge pull request #1748 from jonludlam/event-problems

Event problems
Merge pull request #1749 from simonjbeaumont/ignore-ounit-cruft

Ignore new artifacts of OUnit2 test runs
Convert test suite to OUnit2 before running

This is needed since running an OUnit 1.x test suite using OUnit2 installed
does not return non-zero exit code even on failure or error.

Converting the suite at this point is desirable in favour of converting all the
tests because we can keep writing tests using OUnit 1.x style, making them
backportable to old build environments without OUnit2 (and without this patch).

Signed-off-by: Si Beaumont <simon.beaumont@citrix.com>
arm: robustify the parsing of /proc/cpuinfo

We should not expect there to be x86-only keys. We should ignore any lines
which don't have the 'key: value' format.

Signed-off-by: David Scott <dave.scott@citrix.com>