Changes between Initial Version and Version 1 of DeveloperHowToMigrate


Ignore:
Timestamp:
Jul 24, 2009, 3:16:58 PM (15 years ago)
Author:
Gabriele Pohl
Comment:

Insert content from old wiki

Legend:

Unmodified
Added
Removed
Modified
  • DeveloperHowToMigrate

    v1 v1  
     1[[PageOutline]]
     2== Migrate old os_''youros''.cpp to new class interface ==
     3
     4Christian Franke wrote this quick outline how a migration works, which he already tested with os_linux.cpp.
     5
     6=== Step 1: Move adapter classes into os_''youros''.cpp ===
     7
     8 * Append adapter classes to old module:
     9{{{
     10#!sh
     11$ cat dev_legacy.cpp >> os_youros.cpp
     12[[code]]
     13- Re-configure, this should now detect new interface:
     14[[code format="bash"]]
     15$ ./configure
     16...
     17checking whether os_youros.cpp uses new interface... yes
     18}}}
     19 * This should compile and work!
     20 * Move #includes to top, remove duplicates.
     21 * Remove all dummy functions for controllers not supported on your os (marvell_command_interface, ...).
     22 * Remove corresponding classes (e.g legacy_marvell_device, ...).
     23 * Remove corresponding section from legacy_smart_interface::get_custom_smart_device(). If nothing left, remove this function.
     24 * Rename remaining classes 'legacy_*' to 'youros_*'. Rename namespace 'os' to 'os_youros'.
     25 * This should compile and work!
     26
     27=== Step 2: Merge old functions into class member functions ===
     28
     29'''Old:'''
     30{{{
     31#!c
     32int deviceopen(const char *pathname, char *type)
     33{
     34  ...
     35  int fd = open(pathname, ...);
     36  ...
     37  return fd;
     38}
     39
     40bool youros_smart_device::open()
     41{
     42  m_fd = ::deviceopen(get_dev_name(), (char*)m_mode);
     43  if (m_fd < 0) {
     44    set_err(errno);
     45    return false;
     46  }
     47  return true;
     48}
     49}}}
     50
     51'''New:'''
     52{{{
     53#!cpp
     54bool youros_smart_device::open()
     55{
     56  ...
     57  m_fd = open(get_dev_name(), ...);
     58  if (m_fd < 0) {
     59    set_err(errno);
     60    return false;
     61  }
     62  return true;
     63}
     64}}}
     65
     66'''Old:'''
     67{{{
     68#!c
     69int ata_command_interface(int fd, smart_command_set command, int select, char *data)
     70{
     71  ...
     72  if (ioctl(fd, ...))
     73    return -1;
     74  ...
     75  return 0;
     76}
     77
     78int youros_ata_device::ata_command_interface(smart_command_set command, int select, char * data)
     79{
     80  return ::ata_command_interface(get_fd(), command, select, data);
     81}
     82}}}
     83
     84'''New:'''
     85{{{
     86#!cpp
     87int youros_ata_device::ata_command_interface(smart_command_set command, int select, char * data)
     88{
     89  ...
     90  if (ioctl(get_fd(), ...))
     91    return -1;
     92  ...
     93  return 0;
     94}
     95}}}
     96
     97
     98=== Step 3: Convert SMART-only to full fledged ATA pass through ===
     99
     100 * Change base class of 'youros_ata_device' from 'ata_device_with_command_set' to 'ata_device'.
     101 * Change 'youros_ata_device::ata_command_interface()' to 'youros_ata_device::ata_pass_through()'.
     102 * Add parameter check using ata_cmd_is_ok(in, 'supported features')
     103 * Remove 'switch (command) {....}', set ioctl input struct directly from input registers e.g. 'in.in_regs.*'.
     104 * Remove special handling for SMART STATUS, return result registers in 'out.out_regs' if requested by 'in.out_needed.is_set()'.
     105 * Adjust returns:
     106{{{
     107Replace 'return 0;' by 'return true;'.
     108Replace 'errno = ERR; return -1;' by 'return set_err(ERR, "optional message", ...)'.
     109}}}
     110 * Optional add 48bit ATA pass through support:
     111{{{
     112If 'in.in_regs.is_48bit_cmd()' is set,
     113pass low (in.in_regs.lba_mid) and
     114high (in.in_regs.prev.lba_mid) byte of each register to ioctl.
     115}}}
     116
     117=== Later ===
     118 * Rework device scanning.
     119 * Add/Rework auto-detection (function autodetect_open()).
     120 * remove os_youros.h, each module does only export smart_interface::init().
     121
     122=== Example for Steps 1+2: ===
     123http://smartmontools.cvs.sourceforge.net/viewvc/smartmontools/sm5/os_linux.cpp?r1=1.116&r2=1.117
     124
     125=== Example for Step 3 (3ware only): ===
     126http://smartmontools.cvs.sourceforge.net/viewvc/smartmontools/sm5/os_linux.cpp?r1=1.117&r2=1.118