Skip to content

Draft: libdm refactor: consolidate device_mapper and base directories into libdm

libdm refactor: consolidate device_mapper and base directories into libdm

Overview

This merge request implements a major refactoring of the LVM2 codebase to consolidate the device_mapper and base directories into the existing libdm directory. This consolidation simplifies the codebase structure, reduces duplication, and provides a cleaner API surface for device mapper functionality.

Summary of Changes

The refactoring consists of 22 commits that systematically:

  1. Sync existing libdm components with their device_mapper counterparts to ensure feature parity
  2. Add missing functionality from device_mapper to libdm (RAID, VDO, integrity, cache, writecache)
  3. Consolidate base directory utilities (hash, radix tree, container_of) into libdm
  4. Remove redundant directories (device_mapper and base) after successful migration
  5. Update all references throughout the codebase to use the consolidated libdm API

Key Changes

New Functionality Added to libdm:

  • RAID support: Added RAID target functionality with dm_raid_count_failed_devices and dm_raid_clear_failed_devices functions
  • VDO support: Integrated VDO target functionality for data deduplication
  • Integrity support: Added integrity target functionality for data integrity checking
  • Cache/Writecache support: Integrated cache and writecache target functionality
  • Enhanced data structures: Added radix tree implementation and updated hash implementation
  • Utility functions: Added dm_container_of macro and dm_active_device support

Code Consolidation:

  • Removed ~26,000 lines of duplicated code from device_mapper and base directories
  • Added ~2,000 lines of consolidated functionality to libdm
  • Updated 158 files across the codebase to use the new libdm API
  • Maintained backward compatibility through proper function naming and API design

API Improvements:

  • All device mapper functionality now accessible through a single libdevmapper.h header
  • Consistent naming convention with dm_ prefix for all functions
  • Cleaner separation of concerns within the libdm directory structure
  • Enhanced logging and debugging capabilities

Benefits

  1. Simplified maintenance: Single source of truth for device mapper functionality
  2. Reduced code duplication: Eliminated redundant implementations across directories
  3. Better API design: Consistent interface through libdm
  4. Easier testing: Consolidated test suite for all device mapper functionality
  5. Improved build system: Simplified Makefile structure and dependencies

Testing

The refactoring maintains full backward compatibility and all existing functionality. The changes have been tested to ensure:

  • All LVM2 commands continue to work as expected
  • Device mapper operations function correctly
  • No regressions in existing functionality
  • Proper compilation across different build configurations

mpact

This refactoring represents a significant step forward in code organization and maintainability for the LVM2 project, providing a solid foundation for future development while maintaining full backward compatibility.


Type: Refactoring
Scope: libdm consolidation
Breaking Changes: None (backward compatible)
Files Changed: 158 files
Lines Added: ~2,000
Lines Removed: ~26,000

Edited by Peter Rajnoha

Merge request reports

Loading