Ignore:
Timestamp:
Sep 10, 2009, 2:07:16 AM (15 years ago)
Author:
Bruno Cornec
Message:
  • Change NFS support into a NetFS support to allow for multiple protocol in addition to NFS (NEEDS TESTING)

(Backport from 2.2.9)

File:
1 edited

Legend:

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

    r2376 r2382  
    5454 */
    5555bool g_restoring_live_from_cd = FALSE;
    56 bool g_restoring_live_from_nfs = FALSE;
     56bool g_restoring_live_from_netfs = FALSE;
    5757
    5858extern t_bkptype g_backup_media_type;   // set by main()
     
    164164        mr_asprintf(output, "cdstream");
    165165        break;
    166     case nfs:
    167         mr_asprintf(output, "nfs");
     166    case netfs:
     167        mr_asprintf(output, "netfs");
    168168        break;
    169169    case tape:
     
    12981298    mr_free(tmp);
    12991299
    1300     if (g_ISO_restore_mode || bkpinfo->backup_media_type == iso || bkpinfo->backup_media_type == nfs) {
     1300    if (g_ISO_restore_mode || bkpinfo->backup_media_type == iso || bkpinfo->backup_media_type == netfs) {
    13011301        // BERLIOS --- I'm tempted to do something about this...
    13021302        // Why unmount and remount again and again?
     
    13101310        mr_free(tmp);
    13111311
    1312         if (((bkpinfo->isodir == NULL) && (bkpinfo->nfs_remote_dir == NULL)) || (bkpinfo->prefix == NULL)) {
     1312        if (((bkpinfo->isodir == NULL) && (bkpinfo->netfs_remote_dir == NULL)) || (bkpinfo->prefix == NULL)) {
    13131313            fatal_error("Unable to prepare ISO file name. Please report to dev team");
    13141314        }
    1315         if (bkpinfo->nfs_remote_dir) {
    1316             // NFS
    1317             mr_asprintf(tmp, "%s/%s/%s-%d.iso", bkpinfo->isodir, bkpinfo->nfs_remote_dir, bkpinfo->prefix, cd_number_i_want);
     1315        if (bkpinfo->netfs_remote_dir) {
     1316            // NETFS
     1317            mr_asprintf(tmp, "%s/%s/%s-%d.iso", bkpinfo->isodir, bkpinfo->netfs_remote_dir, bkpinfo->prefix, cd_number_i_want);
    13181318        } else {
    13191319            // ISO
     
    13221322        if (!does_file_exist(tmp)) {
    13231323            mr_free(tmp);
    1324             if (bkpinfo->nfs_remote_dir) {
    1325                 // NFS
    1326                 mr_asprintf(tmp, "%s/isodir/%s/%s-%d.iso", bkpinfo->tmpdir, bkpinfo->nfs_remote_dir, bkpinfo->prefix, cd_number_i_want);
     1324            if (bkpinfo->netfs_remote_dir) {
     1325                // NETFS
     1326                mr_asprintf(tmp, "%s/isodir/%s/%s-%d.iso", bkpinfo->tmpdir, bkpinfo->netfs_remote_dir, bkpinfo->prefix, cd_number_i_want);
    13271327            } else {
    13281328                // ISO
     
    14131413    bkpinfo->nonbootable_backup = FALSE;
    14141414
    1415     // Tape, CD, NFS, ...?
     1415    // Tape, CD, NETFS, ...?
    14161416    srandom(getpid());
    14171417    bkpinfo->backup_media_type =
     
    16471647
    16481648
    1649     case nfs:
    1650         /* Never try to eject a NFS device */
     1649    case netfs:
     1650        /* Never try to eject a NETFS device */
    16511651        bkpinfo->please_dont_eject = TRUE;
    16521652
    1653         /* Initiate bkpinfo nfs_mount path from running environment if not already done */
    1654         if (bkpinfo->nfs_mount == NULL) {
    1655             mr_asprintf(bkpinfo->nfs_mount, "%s", call_program_and_get_last_line_of_output("mount | grep \":\" | cut -d' ' -f1 | head -n1"));
     1653        /* Initiate bkpinfo netfs_mount path from running environment if not already done */
     1654        if (bkpinfo->netfs_mount == NULL) {
     1655            mr_asprintf(bkpinfo->netfs_mount, "%s", call_program_and_get_last_line_of_output("mount | grep \":\" | cut -d' ' -f1 | head -n1"));
    16561656        }
    16571657#ifdef __FreeBSD__
     
    16611661#endif
    16621662        {
    1663             p = popup_and_get_string("NFS dir.", "Please enter path and directory where archives are stored remotely. (Mondo has taken a guess at the correct value. If it is incorrect, delete it and type the correct one.)", bkpinfo->nfs_mount);
     1663            p = popup_and_get_string("Network shared dir.", "Please enter path and directory where archives are stored remotely. (Mondo has taken a guess at the correct value. If it is incorrect, delete it and type the correct one.)", bkpinfo->netfs_mount);
    16641664            if (p == NULL) {
    16651665                log_to_screen("User has chosen not to backup the PC");
    16661666                finish(1);
    16671667            }
    1668             mr_free(bkpinfo->nfs_mount);
    1669             bkpinfo->nfs_mount = p;
     1668            mr_free(bkpinfo->netfs_mount);
     1669            bkpinfo->netfs_mount = p;
    16701670            if (!bkpinfo->restore_data) {
    16711671                if ((bkpinfo->compression_level =
     
    16771677            // check whether already mounted - we better remove
    16781678            // surrounding spaces and trailing '/' for this
    1679             mr_strip_spaces(bkpinfo->nfs_mount);
    1680             if (bkpinfo->nfs_mount[strlen(bkpinfo->nfs_mount) - 1] == '/')
    1681                 bkpinfo->nfs_mount[strlen(bkpinfo->nfs_mount) - 1] = '\0';
    1682             mr_asprintf(command, "mount | grep \"%s \" | cut -d' ' -f3", bkpinfo->nfs_mount);
     1679            mr_strip_spaces(bkpinfo->netfs_mount);
     1680            if (bkpinfo->netfs_mount[strlen(bkpinfo->netfs_mount) - 1] == '/')
     1681                bkpinfo->netfs_mount[strlen(bkpinfo->netfs_mount) - 1] = '\0';
     1682            mr_asprintf(command, "mount | grep \"%s \" | cut -d' ' -f3", bkpinfo->netfs_mount);
    16831683            mr_free(bkpinfo->isodir);
    16841684            mr_asprintf(bkpinfo->isodir, "%s", call_program_and_get_last_line_of_output(command));
     
    17111711            mr_free(command);
    17121712
    1713             p = popup_and_get_string("NFS share", "Which remote NFS share should I mount?", bkpinfo->nfs_mount);
     1713            p = popup_and_get_string("Network share", "Which remote Network share should I mount?", bkpinfo->netfs_mount);
    17141714            if (p == NULL) {
    17151715                log_to_screen("User has chosen not to backup the PC");
    17161716                finish(1);
    17171717            }
    1718             mr_free(bkpinfo->nfs_mount);
    1719             bkpinfo->nfs_mount = p;
     1718            mr_free(bkpinfo->netfs_mount);
     1719            bkpinfo->netfs_mount = p;
    17201720        }
    17211721        /* Initiate bkpinfo isodir path from running environment if mount already done */
    17221722        mr_free(bkpinfo->isodir);
    1723         if (is_this_device_mounted(bkpinfo->nfs_mount)) {
     1723        if (is_this_device_mounted(bkpinfo->netfs_mount)) {
    17241724            mr_asprintf(bkpinfo->isodir, "%s", call_program_and_get_last_line_of_output("mount | grep \":\" | cut -d' ' -f3 | head -n1"));
    17251725
    17261726        } else {
    1727             mr_asprintf(bkpinfo->isodir, "%s/nfsdir", bkpinfo->tmpdir);
     1727            mr_asprintf(bkpinfo->isodir, "%s/netfsdir", bkpinfo->tmpdir);
    17281728            mr_asprintf(command, "mkdir -p %s", bkpinfo->isodir);
    17291729            run_program_and_log_output(command, 5);
     
    17311731
    17321732            if (bkpinfo->restore_data) {
    1733                 mr_asprintf(tmp, "mount -t nfs -o nolock,ro %s %s", bkpinfo->nfs_mount, bkpinfo->isodir);
     1733                if (strstr(bkpinfo->netfs_proto, "sshfs")) {
     1734                    mr_asprintf(tmp, "sshfs -o ro %s %s", bkpinfo->netfs_mount, bkpinfo->isodir);
     1735                } else {
     1736                    mr_asprintf(tmp, "mount -t %s -o nolock,ro %s %s", bkpinfo->netfs_proto, bkpinfo->netfs_mount, bkpinfo->isodir);
     1737                }
    17341738            } else {
    1735                 mr_asprintf(tmp, "mount -t nfs -o nolock %s %s", bkpinfo->nfs_mount, bkpinfo->isodir);
     1739                if (strstr(bkpinfo->netfs_proto, "sshfs")) {
     1740                    mr_asprintf(tmp, "sshfs %s %s", bkpinfo->netfs_mount, bkpinfo->isodir);
     1741                } else {
     1742                    mr_asprintf(tmp, "mount -t %s -o nolock %s %s", bkpinfo->netfs_proto, bkpinfo->netfs_mount, bkpinfo->isodir);
     1743                }
    17361744            }
    17371745            run_program_and_log_output(tmp, 3);
     
    17411749            strcpy(g_selfmounted_isodir, bkpinfo->isodir);
    17421750        }
    1743         if (!is_this_device_mounted(bkpinfo->nfs_mount)) {
     1751        if (!is_this_device_mounted(bkpinfo->netfs_mount)) {
    17441752            popup_and_OK("Please mount that partition before you try to backup to or restore from it.");
    17451753            finish(1);
    17461754        }
    1747         p = popup_and_get_string("Directory", "Which directory within that mountpoint?", bkpinfo->nfs_remote_dir);
     1755        p = popup_and_get_string("Directory", "Which directory within that mountpoint?", bkpinfo->netfs_remote_dir);
    17481756        if (p == NULL) {
    17491757            log_to_screen("User has chosen not to backup the PC");
    17501758            finish(1);
    17511759        }
    1752         mr_free(bkpinfo->nfs_remote_dir);
    1753         bkpinfo->nfs_remote_dir = p;
     1760        mr_free(bkpinfo->netfs_remote_dir);
     1761        bkpinfo->netfs_remote_dir = p;
    17541762
    17551763        // check whether writable - we better remove surrounding spaces for this
    1756         mr_strip_spaces(bkpinfo->nfs_remote_dir);
     1764        mr_strip_spaces(bkpinfo->netfs_remote_dir);
    17571765
    17581766        p = popup_and_get_string("Prefix.", "Please enter the prefix that will be prepended to your ISO filename.  Example: machine1 to obtain machine1-[1-9]*.iso files", bkpinfo->prefix);
     
    17651773        log_msg(3, "prefix set to %s", bkpinfo->prefix);
    17661774
    1767         log_msg(3, "Just set nfs_remote_dir to %s", bkpinfo->nfs_remote_dir);
     1775        log_msg(3, "Just set netfs_remote_dir to %s", bkpinfo->netfs_remote_dir);
    17681776        log_msg(3, "isodir is still %s", bkpinfo->isodir);
    17691777        break;
     
    18731881        bkpinfo->include_paths = p;
    18741882
    1875         mr_asprintf(tmp, "%s", list_of_NFS_mounts_only());
     1883        mr_asprintf(tmp, "%s", list_of_NETFS_mounts_only());
    18761884        if (strlen(tmp) > 2) {
    18771885            mr_strcat(bkpinfo->exclude_paths, " %s",tmp);
     
    19461954
    19471955    if (bkpinfo->backup_media_type == iso
    1948         || bkpinfo->backup_media_type == nfs) {
     1956        || bkpinfo->backup_media_type == netfs) {
    19491957        g_ISO_restore_mode = TRUE;
    19501958    }
     
    19521960// skip
    19531961#else
    1954     if (bkpinfo->backup_media_type == nfs) {
    1955         log_msg(3, "I think the NFS mount is mounted at %s", bkpinfo->isodir);
     1962    if (bkpinfo->backup_media_type == netfs) {
     1963        log_msg(3, "I think the Remote mount is mounted at %s", bkpinfo->isodir);
    19561964    }
    19571965    log_it("isodir = %s", bkpinfo->isodir);
    1958     if (bkpinfo->nfs_mount) {
    1959         log_it("nfs_mount = '%s'", bkpinfo->nfs_mount);
    1960     }
    1961     if (bkpinfo->nfs_user) {
    1962         log_it("nfs_user = '%s'", bkpinfo->nfs_user);
     1966    if (bkpinfo->netfs_mount) {
     1967        log_it("netfs_mount = '%s'", bkpinfo->netfs_mount);
     1968    }
     1969    if (bkpinfo->netfs_user) {
     1970        log_it("netfs_user = '%s'", bkpinfo->netfs_user);
     1971    }
     1972    if (bkpinfo->netfs_proto) {
     1973        log_it("netfs_proto = '%s'", bkpinfo->netfs_proto);
    19631974    }
    19641975#endif
     
    20082019 */
    20092020/**
    2010  * Get a space-separated list of NFS devices and mounts.
     2021 * Get a space-separated list of NETFS devices and mounts.
    20112022 * @return The list created.
    20122023 * @note The return value points to static data that will be overwritten with each call.
    20132024 */
    2014 char *list_of_NFS_devices_and_mounts(void)
     2025char *list_of_NETFS_devices_and_mounts(void)
    20152026{
    20162027    char *exclude_these_devices = NULL;
     
    20182029    static char result_sz[1024];
    20192030
    2020     mr_asprintf(exclude_these_directories,"%s",list_of_NFS_mounts_only());
    2021     mr_asprintf(exclude_these_devices,"%s", call_program_and_get_last_line_of_output("tr -s '\t' ' ' < /etc/fstab | grep -E '( (coda|ncpfs|nfs|nfs4|smbfs|cifs|afs|gfs|ocfs|ocfs2|mvfs|nsspool|nsvol) )' | cut -d' ' -f1 | tr -s '\n' ' ' | awk '{print $0;}'"));
     2031    mr_asprintf(exclude_these_directories,"%s",list_of_NETFS_mounts_only());
     2032    mr_asprintf(exclude_these_devices,"%s", call_program_and_get_last_line_of_output("tr -s '\t' ' ' < /etc/fstab | grep -E '( (coda|ncpfs|sshfs|nfs|nfs4|smbfs|cifs|afs|gfs|ocfs|ocfs2|mvfs|nsspool|nsvol) )' | cut -d' ' -f1 | tr -s '\n' ' ' | awk '{print $0;}'"));
    20222033    snprintf(result_sz, 1023, "%s %s", exclude_these_directories, exclude_these_devices);
    20232034    mr_free(exclude_these_devices);
     
    20302041
    20312042/**
    2032  * Get a space-separated list of NFS mounts.
     2043 * Get a space-separated list of NETFS mounts.
    20332044 * @return The list created.
    20342045 * @note The return value points to static data that will be overwritten with each call.
    20352046 * @bug Even though we only want the mounts, the devices are still checked.
    20362047 */
    2037 char *list_of_NFS_mounts_only(void)
     2048char *list_of_NETFS_mounts_only(void)
    20382049{
    20392050    char *exclude_these_directories = NULL;
    20402051    static char result_sz[512];
    20412052
    2042     mr_asprintf(exclude_these_directories,"%s", call_program_and_get_last_line_of_output("mount -t coda,ncpfs,nfs,nfs4,smbfs,cifs,afs,gfs,ocfs,ocfs2,mvfs,nsspool,nssvol | tr -s '\t' ' ' | cut -d' ' -f3 | tr -s '\n' ' ' | awk '{print $0;}'"));
     2053    mr_asprintf(exclude_these_directories,"%s", call_program_and_get_last_line_of_output("mount -t coda,ncpfs,fuse.sshfs,nfs,nfs4,smbfs,cifs,afs,gfs,ocfs,ocfs2,mvfs,nsspool,nssvol | tr -s '\t' ' ' | cut -d' ' -f3 | tr -s '\n' ' ' | awk '{print $0;}'"));
    20432054    snprintf(result_sz, 511, "%s", exclude_these_directories);
    20442055    mr_free(exclude_these_directories);
     
    20942105    mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("LANGUAGE=C df -m -P -t nonfs,msdosfs,ntfs,ntfs-3g,smbfs,smb,cifs,afs,gfs,ocfs,ocfs2,mvfs,nsspool,nssvol | grep -vE \"none|Filesystem\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'"));
    20952106#else
    2096     mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("LANGUAGE=C df -m -P -x nfs -x nfs4 -x vfat -x ntfs -x ntfs-3g -x smbfs -x smb -x cifs -x afs -x gfs -x ocfs -x ocfs2 -x mvfs -x nsspool -x nssvol -x iso9660 | grep -vE \"none|Filesystem|/dev/shm\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'"));
     2107    mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("LANGUAGE=C df -m -P -x nfs -x nfs4 -x fuse.sshfs -x vfat -x ntfs -x ntfs-3g -x smbfs -x smb -x cifs -x afs -x gfs -x ocfs -x ocfs2 -x mvfs -x nsspool -x nssvol -x iso9660 | grep -vE \"none|Filesystem|/dev/shm\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'"));
    20972108#endif
    20982109
     
    25352546    struct stat buf;
    25362547#endif
    2537     log_msg(0, "Looking for partition table format type");
    25382548    mr_asprintf(fdisk, "/sbin/parted2fdisk");
    2539     log_msg(1, "Using %s", fdisk);
    25402549    mr_asprintf(command, "%s -l %s | grep 'EFI GPT'", fdisk, drive);
    25412550    mr_free(fdisk);
Note: See TracChangeset for help on using the changeset viewer.