Changeset 2527


Ignore:
Timestamp:
Jan 7, 2010, 7:28:10 PM (9 years ago)
Author:
bruno
Message:

r3736@localhost: bruno | 2010-01-07 17:58:32 +0100

  • Fix #383 by using pvdisplay instead of relying on 8e as partition type
  • Try to fix #384 by always excluding the dfs per users wish
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mondo/src/common/libmondo-devices.c

    r2525 r2527  
    16571657    ********/
    16581658    if (strncmp(dsf, "/dev/", 5)) {
    1659         log_msg (5, "%s does not start with /dev/ and (probably) is not a  device special file", dsf);
     1659        log_msg (4, "%s does not start with /dev/ and (probably) is not a  device special file", dsf);
    16601660        return (-1);
    16611661    }
    1662     log_msg(5, "  %s looks like a device special file", dsf);
     1662    log_msg(4, "  %s looks like a device special file", dsf);
    16631663    /* Verify that the dsf exists */
    16641664    mr_asprintf(&command, "ls -al %s 2>/dev/null | wc -l", dsf);
     
    16751675        return (1);
    16761676    }
    1677     log_msg(5, "  %s device special file exists", dsf);
     1677    log_msg(4, "  %s device special file exists", dsf);
    16781678
    16791679    /* Get a list of the mounted file systems */
     
    16891689    ********/
    16901690    mr_asprintf(&command, "parted2fdisk -l %s 2>/dev/null|grep -E \"^/dev/\"|awk '{printf(\"%%s \", $1)}END{print \"\"}'", dsf);
    1691     log_msg(4, "Executing: %s", command);
     1691    log_msg(5, "Executing: %s", command);
    16921692    mr_asprintf(&partition_list, "%s", call_program_and_get_last_line_of_output(command));
    16931693    paranoid_free(command);
     
    17041704        lastpos = 0;
    17051705        while ((token = mr_strtok(partition_list, token_chars, &lastpos)) != NULL) {
    1706             log_msg (5, "Found partition: %s", token);
     1706            log_msg (4, "Found partition: %s", token);
    17071707            strcpy(partitions[i++], token);
    17081708            mr_free(token);
     
    17111711    }
    17121712    mr_free(partition_list);
    1713  
     1713
     1714    /* In any case we want to exclude the dsf itself from all MondRescue activities
     1715     * at restore time (LVM, fdisk, ...) so we want it in our exclude_dev list */
     1716    if ((DSFptr = find_device_in_list(dsf)) == NULL) {
     1717        log_msg (4, "Can't find device %s in mounted file systems list", dsf);
     1718        paranoid_free(tmp);
     1719        mr_free(token);
     1720        return (1);
     1721    }
     1722    DSFptr->check = 1;
     1723
    17141724    /*  For the rest ndsf is the new dsf to deal with */
    17151725    /********
     
    17471757        mr_asprintf(&command, "parted2fdisk -l %s 2>/dev/null | awk '{if(($1==\"%s\")&&(toupper($0) ~ \"SWAP\")){print $1;exit}}'",
    17481758          ndsf, partitions[i]);
    1749         log_msg(4, "  Running: %s", command);
     1759        log_msg(5, "  Running: %s", command);
    17501760        mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    17511761        paranoid_free(command);
    1752         log_msg(4, "  Return value: %s", tmp);
     1762        log_msg(5, "  Return value: %s", tmp);
    17531763        c = strlen(tmp);
    17541764        paranoid_free(tmp);
     
    17751785        /* It's not swap and it's not mounted. See if it's LVM */
    17761786        log_msg(4, "  It's not mounted. Checking to see if it's LVM...");
    1777         /* Get the partition ID; 8e for LVM */
    1778         mr_asprintf(&command, "parted2fdisk -l %s |awk '{if($1 ~ \"^%s\"){print $5}}'", ndsf, partitions[i]);
    1779         log_msg(4, "  Running: %s", command);
     1787        /* Check for LVM */
     1788        mr_asprintf(&command, "pvdisplay -c %s | grep '%s:' 2> /dev/null", partitions[i], partitions[i]);
     1789        log_msg(5, "  Running: %s", command);
    17801790        mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    17811791        paranoid_free(command);
    17821792        if (strlen(tmp)) {
    1783             log_msg(4, "  Partition ID: %s", tmp);
    1784             if (!strcasecmp(tmp, "8e")) {
    1785                 /* It's LVM: Find the VG it's in */
    1786                 log_msg(4, "  It's LVM: Find the VG it's in...");
    1787                 mr_asprintf(&command, "pvdisplay -v %s 2>/dev/null|grep \"VG Name\"|awk '{print $NF}'", partitions[i]);
    1788                 log_msg(4, "  Running: %s", command);
    1789                 strcpy(VG, call_program_and_get_last_line_of_output(command));
     1793            log_msg(4, "Found an LVM partition at %s. Find the VG it's in...", partitions[i]);
     1794            /* It's LVM: Find the VG it's in */
     1795            mr_asprintf(&command, "pvdisplay -v %s 2>/dev/null|grep \"VG Name\"|awk '{print $NF}'", partitions[i]);
     1796            log_msg(5, "  Running: %s", command);
     1797            strcpy(VG, call_program_and_get_last_line_of_output(command));
     1798            paranoid_free(command);
     1799            log_msg(4, "  Volume Group: %s", VG);
     1800            if (strlen(VG)) {
     1801                /* Found the Volume Group. Now find all of the VG's mount points */
     1802                log_msg(4, "  Found the Volume Group. Now find all of the VG's mount points");
     1803                mr_asprintf(&command, "mount 2>/dev/null|grep -E \"/dev/mapper/%s-|/dev/%s/\"|awk '{printf(\"%%s \",$3)}END{print \"\"}'", VG, VG);
     1804                log_msg(5, "  Running: %s", command);
     1805                mr_asprintf(&mount_list, "%s", call_program_and_get_last_line_of_output(command));
    17901806                paranoid_free(command);
    1791                 log_msg(4, "  Volume Group: %s", VG);
    1792                 if (strlen(VG)) {
    1793                     /* Found the Volume Group. Now find all of the VG's mount points */
    1794                     log_msg(4, "  Found the Volume Group. Now find all of the VG's mount points");
    1795                     mr_asprintf(&command, "mount 2>/dev/null|grep -E \"/dev/mapper/%s-|/dev/%s/\"|awk '{printf(\"%%s \",$3)}END{print \"\"}'", VG, VG);
    1796                     log_msg(4, "  Running: %s", command);
    1797                     mr_asprintf(&mount_list, "%s", call_program_and_get_last_line_of_output(command));
     1807                log_msg(4, "  VG %s mount_list: %s", VG, mount_list);
     1808                lastpos = 0;
     1809                while ((token = mr_strtok(mount_list, token_chars, &lastpos)) != NULL) {
     1810                    log_msg (5, "mount point token: %s", token);
     1811                    if ((DSFptr = find_mount_point_in_list(token)) == NULL) {
     1812                        log_msg (4, "Can't find mount point %s in mounted file systems list", token);
     1813                        paranoid_free(tmp);
     1814                        mr_free(token);
     1815                        return (1);
     1816                    }
     1817                    DSFptr->check = 1;
     1818                    mr_free(token);
     1819                }
     1820                /********
     1821                 * Now we want to see if there are any software raid devices using
     1822                 * any of the Logical Volumes on the Volume Group.
     1823                 *******/
     1824                paranoid_free(mount_list);
     1825
     1826                mr_asprintf(&command, "%s", "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'");
     1827                log_msg (5, "Running: %s", command);
     1828                mr_asprintf(&mount_list, "%s", call_program_and_get_last_line_of_output(command));
     1829                paranoid_free(command);
     1830                log_msg(4, "  Software raid device list: %s", mount_list);
     1831                lastpos = 0;
     1832                while ((token = mr_strtok(mount_list, token_chars, &lastpos)) != NULL) {
     1833                    mr_asprintf(&command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, VG);
     1834                    log_msg (5, "Running: %s", command);
     1835                    paranoid_free(tmp);
     1836                    mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    17981837                    paranoid_free(command);
    1799                     log_msg(4, "  VG %s mount_list: %s", VG, mount_list);
    1800                     lastpos = 0;
    1801                     while ((token = mr_strtok(mount_list, token_chars, &lastpos)) != NULL) {
    1802                         log_msg (5, "mount point token: %s", token);
    1803                         if ((DSFptr = find_mount_point_in_list(token)) == NULL) {
    1804                             log_msg (4, "Can't find mount point %s in mounted file systems list", token);
     1838                    log_msg(4, "Number of Software raid device: %s", tmp);
     1839                    if (atoi(tmp)) {
     1840                        /* This device is on our disk */
     1841                        if ((DSFptr = find_device_in_list(token)) == NULL) {
     1842                            log_msg (4, "Can't find device %s in mounted file systems list", token);
    18051843                            paranoid_free(tmp);
    18061844                            mr_free(token);
     
    18081846                        }
    18091847                        DSFptr->check = 1;
    1810                         mr_free(token);
    18111848                    }
    1812                     /********
    1813                      * Now we want to see if there are any software raid devices using
    1814                      * any of the Logical Volumes on the Volume Group.
    1815                      *******/
    1816                     paranoid_free(mount_list);
    1817 
    1818                     mr_asprintf(&command, "%s", "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'");
    1819                     log_msg (5, "Running: %s", command);
    1820                     mr_asprintf(&mount_list, "%s", call_program_and_get_last_line_of_output(command));
    1821                     paranoid_free(command);
    1822                     log_msg(4, "  Software raid device list: %s", mount_list);
    1823                     lastpos = 0;
    1824                     while ((token = mr_strtok(mount_list, token_chars, &lastpos)) != NULL) {
    1825                         mr_asprintf(&command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, VG);
    1826                         log_msg (5, "Running: %s", command);
    1827                         paranoid_free(tmp);
    1828                         mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    1829                         paranoid_free(command);
    1830                         log_msg(4, "Number of Software raid device: %s", tmp);
    1831                         if (atoi(tmp)) {
    1832                             /* This device is on our disk */
    1833                             if ((DSFptr = find_device_in_list(token)) == NULL) {
    1834                                 log_msg (4, "Can't find device %s in mounted file systems list", token);
    1835                                 paranoid_free(tmp);
    1836                                 mr_free(token);
    1837                                 return (1);
    1838                             }
    1839                             DSFptr->check = 1;
    1840                         }
    1841                     }
    1842                     mr_free(token);
    1843                     paranoid_free(mount_list);
    1844                 } else {
    1845                     log_msg (4, "Error finding Volume Group for partition %s", partitions[i]);
    1846                     paranoid_free(tmp);
    1847                     return (1);
    18481849                }
     1850                mr_free(token);
     1851                paranoid_free(mount_list);
     1852            } else {
     1853                log_msg (4, "Error finding Volume Group for partition %s", partitions[i]);
    18491854                paranoid_free(tmp);
    1850                 continue;
    1851             }
     1855                return (1);
     1856            }
     1857            paranoid_free(tmp);
     1858            continue;
    18521859        } else {
    18531860            log_msg (4, "Error finding partition type for the partition %s", partitions[i]);
     
    19171924    while (DSFptr != NULL) {
    19181925        if (DSFptr->check) {
    1919             log_msg (5, "%s is mounted on %s and is on disk %s\n", DSFptr->device, DSFptr->mount_point, ndsf);
     1926            log_msg (4, "%s is mounted on %s and is on disk %s\n", DSFptr->device, DSFptr->mount_point, ndsf);
    19201927            strcat(*included_dsf_list, DSFptr->mount_point);
    19211928            strcat(*included_dsf_list, " ");
Note: See TracChangeset for help on using the changeset viewer.