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:
- Int pvcreate (struct cmd_context * cmd, int argc, char ** argv)
- {
- Int I, R;
- Int ret = ecmd_processed;
- Struct pvcreate_params pp;
- If (! Argc ){
- Log_error ("Please enter a physical volume path ");
- Return einvalid_cmd_line;
- }
- If (arg_count (CMD, restorefile_arg )&&! Arg_count (CMD, uuidstr_arg )){
- Log_error ("-- UUID is required with -- restorefile ");
- Return einvalid_cmd_line;
- }
- If (arg_count (CMD, uuidstr_arg) & argc! = 1 ){
- Log_error ("can only set UUID on one volume at once ");
- Return einvalid_cmd_line;
- }
- If (arg_count (CMD, yes_arg )&&! Arg_count (CMD, force_arg )){
- Log_error ("option Y can only be given with option F ");
- Return einvalid_cmd_line;
- }
- If (arg_int_value (CMD, labelsector_arg, 0)> = label_scan_sectors ){
- Log_error ("labelsector must be less than % lu ",
- Label_scan_sectors );
- Return einvalid_cmd_line;
- }
- If (! (CMD-> FMT-> Features & fmt_mdas )&&
- (Arg_count (CMD, metadatacopies_arg) |
- Arg_count (CMD, metadatasize_arg ))){
- Log_error ("metadata parameters only apply to text format ");
- Return einvalid_cmd_line;
- }
- If (arg_count (CMD, metadatacopies_arg )&&
- Arg_int_value (CMD, metadatacopies_arg,-1)> 2 ){
- Log_error ("metadatacopies may only be 0, 1 or 2 ");
- Return einvalid_cmd_line;
- }
- If (arg_count (CMD, zero_arg ))
- Pp. Zero = strcmp (arg_str_value (CMD, zero_arg, "Y"), "N ");
- Else if (arg_count (CMD, restorefile_arg) | arg_count (CMD, uuidstr_arg ))
- Pp. Zero = 0;
- Else
- Pp. Zero = 1;
- For (I = 0; I <argc; I ++ ){
- R = pvcreate_single (CMD, argv [I], & PP );
- If (r> RET)
- Ret = R;
- If (sigint_caught ())
- Return ret;
- }
- Return ret;
- }
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:
- If (arg_count (CMD, uuidstr_arg )){
- UUID = arg_str_value (CMD, uuidstr_arg ,"");
- If (! Id_read_format (& ID, UUID ))
- Return einvalid_cmd_line;
- If (Dev = device_from_pvid (CMD, & ID ))&&
- (Dev! = Dev_cache_get (pv_name, CMD-> filter ))){
- Log_error ("UUID % s already in use on/" % S/"", UUID,
- Dev_name (Dev ));
- Return ecmd_failed;
- }
- IDP = & ID;
- }
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.
- If (arg_count (CMD, restorefile_arg )){
- Restorefile = arg_str_value (CMD, restorefile_arg ,"");
- /* The uuid won't already exist */
- Init_partial (1 );
- If (! (VG = backup_read_vg (CMD, null, restorefile ))){
- Log_error ("unable to read volume group from % s ",
- Restorefile );
- Return ecmd_failed;
- }
- Init_partial (0 );
- If (! (Existing_pv = find_pv_in_vg_by_uuid (VG, IDP ))){
- Log_error ("can't find UUID % s in backup file % s ",
- UUID, restorefile );
- Return ecmd_failed;
- }
- Pe_start = pv_pe_start (existing_pv );
- Extent_size = pv_pe_size (existing_pv );
- Extent_count = pv_pe_count (existing_pv );
- }
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 ~