IH-657: Reduce XAPI code duplication #5856
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Best reviewed by commit
Several fairly large modules are duplicated in XAPI - historically this happened due to the repositories being separate, more friction in adding inter-dependencies, and the additional difficulty of opening PRs in several of them, which is why it was easier to copy and paste code sometimes.
This is problematic because these have already been (or could be in the future) modified separately, without modifying (or improving, fixing) an identical interface in a different part of the repository.
This PR removes duplicated modules in:
ocaml/vhd-tool/src/xenstore.ml
andocaml/libs/ezxenstore/core/xenstore.ml
diff ocaml/vhd-tool/src/xenstore.ml ocaml/libs/ezxenstore/core/xenstore.ml
)ocaml/vhd-tool/src/cohttp_unbuffered_io.ml
andocaml/xen-api-client/lwt/cohttp_unbuffered_io.ml
The only difference was in the type of the channel implementations used. Therefore, the module was converted into a functor.
module
CBuf
inocaml/libs/xapi-stdext/lib/xapi-stdext-unix/unixext.ml
andocaml/xapi-idl/lib/posix_channel.ml
====
Several other duplicated modules were found during the development of this PR:
module
Observer
inocaml/xapi-idl/xen/xenops_interface.ml
andocaml/xapi-idl/cluster/cluster_interface.ml
This change was not undertaken as, even though the modules are identical, they capture some of the functions from external modules they're in, which are different enough to cause tests to fail.
module
Delay
inocaml/libs/xapi-stdext/lib/xapi-stdext-threads/threadext.ml
andocaml/message-switch/unix/protocol_unix_scheduler.ml
These are somewhat emblematic of the issue described above - one module was changed to
epoll
inmaster
while the other is currently usingselect
simply because they are duplicated. This will be fixed once the final epoll PRs are merged (See 14eca11 in [epoll] Unix.select conversion: replace with stdext modules/calls or polly calls #5705)I've used really primitive ways of finding duplicated modules. One way to do this is:
Another way is to use
duplo
, which hashes parts of files to find duplicated sections of arbitrary lengths (paper), and then look formodule
in its massive outputThis is obviously only looking for duplicated module names as indications of duplicated module code, doesn't capture cases of duplicated code outside of modules (or inside of modules but without identical names). This could by imitated by manually parsing through the out.txt (practically impossible), or varying the minimum duplicated lines parameter with
duplo -ml XX
. This was not yet undertaken as modules are easier to factor out than parts of freestanding code.