LVM code analysis (6) -- pvcreate

Source: Internet
Author: User
How to enter the command pvcreate/dev/sda0 through LVM, and then convert it to the process of calling pvcreate, the previous calculations are basically clear, more details need to be improved in the future. The pvcreate Function Code is as follows:
  1. Int pvcreate (struct cmd_context * cmd, int argc, char ** argv)
  2. {
  3. Int I, R;
  4. Int ret = ecmd_processed;
  5. Struct pvcreate_params pp;
  6. If (! Argc ){
  7. Log_error ("Please enter a physical volume path ");
  8. Return einvalid_cmd_line;
  9. }
  10. If (arg_count (CMD, restorefile_arg )&&! Arg_count (CMD, uuidstr_arg )){
  11. Log_error ("-- UUID is required with -- restorefile ");
  12. Return einvalid_cmd_line;
  13. }
  14. If (arg_count (CMD, uuidstr_arg) & argc! = 1 ){
  15. Log_error ("can only set UUID on one volume at once ");
  16. Return einvalid_cmd_line;
  17. }
  18. If (arg_count (CMD, yes_arg )&&! Arg_count (CMD, force_arg )){
  19. Log_error ("option Y can only be given with option F ");
  20. Return einvalid_cmd_line;
  21. }
  22. If (arg_int_value (CMD, labelsector_arg, 0)> = label_scan_sectors ){
  23. Log_error ("labelsector must be less than % lu ",
  24. Label_scan_sectors );
  25. Return einvalid_cmd_line;
  26. }
  27. If (! (CMD-> FMT-> Features & fmt_mdas )&&
  28. (Arg_count (CMD, metadatacopies_arg) |
  29. Arg_count (CMD, metadatasize_arg ))){
  30. Log_error ("metadata parameters only apply to text format ");
  31. Return einvalid_cmd_line;
  32. }
  33. If (arg_count (CMD, metadatacopies_arg )&&
  34. Arg_int_value (CMD, metadatacopies_arg,-1)> 2 ){
  35. Log_error ("metadatacopies may only be 0, 1 or 2 ");
  36. Return einvalid_cmd_line;
  37. }
  38. If (arg_count (CMD, zero_arg ))
  39. Pp. Zero = strcmp (arg_str_value (CMD, zero_arg, "Y"), "N ");
  40. Else if (arg_count (CMD, restorefile_arg) | arg_count (CMD, uuidstr_arg ))
  41. Pp. Zero = 0;
  42. Else
  43. Pp. Zero = 1;
  44. For (I = 0; I <argc; I ++ ){
  45. R = pvcreate_single (CMD, argv [I], & PP );
  46. If (r> RET)
  47. Ret = R;
  48. If (sigint_caught ())
  49. Return ret;
  50. }
  51. Return ret;
  52. }

From the beginning to the end of line 51, all are judged and processed by the parameters carried by the command. skip this step without any restrictions and wait until the request is used. The for loop starting with line 53 calls the pvcreate_single function for each device.

In pvcreate_single, another depressing statement is displayed:
Struct ID
Like the previous Arg structure and the macro definition of Arg, I cannot jump to the correct se. Ft.

Continue:

  1. If (arg_count (CMD, uuidstr_arg )){
  2. UUID = arg_str_value (CMD, uuidstr_arg ,"");
  3. If (! Id_read_format (& ID, UUID ))
  4. Return einvalid_cmd_line;
  5. If (Dev = device_from_pvid (CMD, & ID ))&&
  6. (Dev! = Dev_cache_get (pv_name, CMD-> filter ))){
  7. Log_error ("UUID % s already in use on/" % S/"", UUID,
  8. Dev_name (Dev ));
  9. Return ecmd_failed;
  10. }
  11. IDP = & ID;
  12. }

In this example, you can obtain the device and determine whether the device is used. The device ID is assigned to the ID variable, and the IDP points to the ID.

  1. If (arg_count (CMD, restorefile_arg )){
  2. Restorefile = arg_str_value (CMD, restorefile_arg ,"");
  3. /* The uuid won't already exist */
  4. Init_partial (1 );
  5. If (! (VG = backup_read_vg (CMD, null, restorefile ))){
  6. Log_error ("unable to read volume group from % s ",
  7. Restorefile );
  8. Return ecmd_failed;
  9. }
  10. Init_partial (0 );
  11. If (! (Existing_pv = find_pv_in_vg_by_uuid (VG, IDP ))){
  12. Log_error ("can't find UUID % s in backup file % s ",
  13. UUID, restorefile );
  14. Return ecmd_failed;
  15. }
  16. Pe_start = pv_pe_start (existing_pv );
  17. Extent_size = pv_pe_size (existing_pv );
  18. Extent_count = pv_pe_count (existing_pv );
  19. }

The following code is fast. It should be constructed based on restorefile or create a new VG, then obtain the existing PV, and obtain pe_start, extent_size, extent_count.
Reading this discontinuous code is really depressing. If you can debug it and see what the input parameter is. Alas ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.