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-cli.c

    r2338 r2382  
    5555static void free_mounted_fs_list (void);
    5656static int get_dsf_mount_list (const char *dsf, char **included_dsf_list, char **excluded_dsf_list);
    57 static int create_list_of_non_NFS_mounted_file_systems (void);
     57static int create_list_of_non_NETFS_mounted_file_systems (void);
    5858static MOUNTED_FS_STRUCT *find_mount_point_in_list (const char *mount_point);
    5959static MOUNTED_FS_STRUCT *find_device_in_list (const char *device);
     
    162162/**
    163163 * Frees the memory for all of the structures on the linked list of
    164  * all of the non-NFS mounted file systems.
     164 * all of the non-NETFS mounted file systems.
    165165 */
    166166static void free_mounted_fs_list (void) {
     
    179179
    180180/**
    181  * Creates a singly linked list of all of the non-NFS mounted file systems.
     181 * Creates a singly linked list of all of the non-NETFS mounted file systems.
    182182 * @param DSFptr A pointer  to the structure MOUNTED_FS_STRUCT used to hold
    183183 * the list of mounted file systems.
     
    197197
    198198/**
    199  * Find the structure, in the singly linked list of all of the non-NFS
     199 * Find the structure, in the singly linked list of all of the non-NETFS
    200200 * mounted file systems, that contains the specified device.
    201201 * @param device The device to find
     
    218218
    219219/**
    220  * Find the structure, in the singly linked list of all of the non-NFS
     220 * Find the structure, in the singly linked list of all of the non-NETFS
    221221 * mounted file systems, that contains the specified mount point.
    222222 * @param mount_point The mount point to find
     
    239239
    240240/**
    241  * Creates a linked list of all of the non-NFS mounted file systems.
     241 * Creates a linked list of all of the non-NETFS mounted file systems.
    242242 * We use a linked list because we don't know how many  mounted file
    243243 * there are (and there can be a lot).
    244244 * @return 0 on success and greated than 0 on failure.
    245245 */
    246 static int create_list_of_non_NFS_mounted_file_systems (void)
     246static int create_list_of_non_NETFS_mounted_file_systems (void)
    247247{
    248248    int i = 0;
     
    372372
    373373    /* Get a list of the mounted file systems */
    374     if (create_list_of_non_NFS_mounted_file_systems()) {
     374    if (create_list_of_non_NETFS_mounted_file_systems()) {
    375375        log_to_screen ("Could not get the list of mounted file systems");
    376376        return (1);
     
    967967
    968968    if (flag_set['n']) {
    969         mr_free(bkpinfo->nfs_mount);
    970         mr_asprintf(bkpinfo->nfs_mount, "%s", flag_val['n']);
     969        mr_free(bkpinfo->netfs_mount);
     970        mr_asprintf(bkpinfo->netfs_mount, "%s", flag_val['n']);
    971971        if (!flag_set['d']) {
    972             mr_free(bkpinfo->nfs_remote_dir);
    973             mr_asprintf(bkpinfo->nfs_remote_dir, "/");
    974         }
    975         /* test if we specified a user for the NFS dialog */
    976         p = strchr(bkpinfo->nfs_mount, '@');
     972            mr_free(bkpinfo->netfs_remote_dir);
     973            mr_asprintf(bkpinfo->netfs_remote_dir, "/");
     974        }
     975        /* test for protocol */
     976        p = strchr(bkpinfo->netfs_mount, ':');
     977        if (p == NULL) {
     978            /* protocol not found abort */
     979            fatal_error("No protocol specified for remote share mount. Please do man mondoarchive as syntax changed");
     980        } else {
     981            /* Proto found. Store the 2 values */
     982            bkpinfo->netfs_proto = bkpinfo->netfs_mount;
     983            p++;
     984            if (*p != '/') {
     985                fatal_error("No protocol correctly specified for remote share mount. Use protocol://server:share");
     986            }
     987            p++;
     988            if (*p != '/') {
     989                fatal_error("No protocol correctly specified for remote share mount. Use protocol://server:share");
     990            }
     991            bkpinfo->netfs_mount = p;
     992            /* new netfs mount - remove :// from proto */
     993            p--;
     994            p--;
     995            p--;
     996            *p = '\0';
     997        }
     998        /* test if we specified a user */
     999        p = strchr(bkpinfo->netfs_mount, '@');
    9771000        if (p != NULL) {
    9781001            /* User found. Store the 2 values */
    979             bkpinfo->nfs_user = bkpinfo->nfs_mount;
     1002            bkpinfo->netfs_user = bkpinfo->netfs_mount;
    9801003            p++;
    981             /* new NFS mount */
    982             bkpinfo->nfs_mount = p;
     1004            /* new netfs mount */
     1005            bkpinfo->netfs_mount = p;
    9831006            p--;
    9841007            *p = '\0';
    9851008        }
    986         mr_asprintf(tmp1, "mount | grep -E \"^%s[/]* .*\" | cut -d' ' -f3", bkpinfo->nfs_mount);
     1009        mr_asprintf(tmp1, "mount | grep -E \"^%s[/]* .*\" | cut -d' ' -f3", bkpinfo->netfs_mount);
    9871010        mr_free(bkpinfo->isodir);
    9881011        mr_asprintf(bkpinfo->isodir, "%s", call_program_and_get_last_line_of_output(tmp1));
     
    9901013
    9911014        if (strlen(bkpinfo->isodir) < 3) {
    992             log_to_screen("NFS share is not mounted. Trying to mount it for you.\n");
    993             mr_asprintf(tmp1, "mount %s", bkpinfo->nfs_mount);
     1015            log_to_screen("Network share is not mounted. Trying to mount it for you.\n");
     1016            if (strstr(bkpinfo->netfs_proto, "sshfs")) {
     1017                mr_asprintf(tmp1, "sshfs %s", bkpinfo->netfs_mount);
     1018            } else {
     1019                mr_asprintf(tmp1, "mount %s", bkpinfo->netfs_mount);
     1020            }
    9941021            i = system(tmp1);
    9951022            mr_free(tmp1);
    9961023            if (i) {
    997                 log_to_screen("Unable to mount NFS share %s. Please mount manually.\n", bkpinfo->nfs_mount);
     1024                log_to_screen("Unable to mount Network share %s. Please mount manually.\n", bkpinfo->netfs_mount);
    9981025                retval++;
    9991026            } else {
    1000                 mr_asprintf(tmp1, "mount | grep -E \"^%s[/]* .*\" | cut -d' ' -f3", bkpinfo->nfs_mount);
     1027                mr_asprintf(tmp1, "mount | grep -E \"^%s[/]* .*\" | cut -d' ' -f3", bkpinfo->netfs_mount);
    10011028                mr_free(bkpinfo->isodir);
    10021029                mr_asprintf(bkpinfo->isodir, "%s", call_program_and_get_last_line_of_output(tmp1));
     
    10051032                if (strlen(bkpinfo->isodir) < 3) {
    10061033                    retval++;
    1007                     log_to_screen("NFS share %s is strangely not mounted. Please mount manually...\n", bkpinfo->nfs_mount);
     1034                    log_to_screen("Network share %s is strangely not mounted. Please mount manually...\n", bkpinfo->netfs_mount);
    10081035                }
    10091036            }
    10101037        }
    1011         log_msg(3, "mount = %s", bkpinfo->nfs_mount);
     1038        log_msg(3, "mount = %s", bkpinfo->netfs_mount);
    10121039        log_msg(3, "isodir= %s", bkpinfo->isodir);
    10131040    }
     
    10231050    }
    10241051    if (flag_set['n']) {
    1025         bkpinfo->backup_media_type = nfs;
    1026         /* Never try to eject a NFS device */
     1052        bkpinfo->backup_media_type = netfs;
     1053        /* Never try to eject a Network device */
    10271054        bkpinfo->please_dont_eject = TRUE;
    10281055    }
     
    11341161    }
    11351162
    1136     if ((flag_set['N']) && (! bkpinfo->restore_data))       // exclude NFS mounts & devices
     1163    if ((flag_set['N']) && (! bkpinfo->restore_data))       // exclude Network mounts & devices
    11371164    {
    1138         mr_asprintf(psz, "%s", list_of_NFS_mounts_only());
     1165        mr_asprintf(psz, "%s", list_of_NETFS_mounts_only());
    11391166        mr_strcat(bkpinfo->exclude_paths, " %s ", psz);
    11401167        mr_free(psz);
     
    12011228    }
    12021229
    1203     if (flag_set['d']) {        /* backup directory (if ISO/NFS) */
     1230    if (flag_set['d']) {        /* backup directory (if ISO/NETFS) */
    12041231        if (flag_set['i']) {
    12051232            mr_free(bkpinfo->isodir);
     
    12121239            mr_free(tmp1);
    12131240        } else if (flag_set['n']) {
    1214             mr_free(bkpinfo->nfs_remote_dir);
    1215             mr_asprintf(bkpinfo->nfs_remote_dir, "%s", flag_val['d']);
     1241            mr_free(bkpinfo->netfs_remote_dir);
     1242            mr_asprintf(bkpinfo->netfs_remote_dir, "%s", flag_val['d']);
    12161243        } else {                /* backup device (if tape/CD-R/CD-RW) */
    12171244            mr_free(bkpinfo->media_device);
     
    12211248
    12221249    if ((flag_set['n']) && (! bkpinfo->restore_data)) {
    1223         mr_asprintf(tmp1,"%s/%s/.dummy.txt", bkpinfo->isodir,bkpinfo->nfs_remote_dir);
    1224         if (bkpinfo->nfs_user) {
    1225             mr_asprintf(tmp2, "su - %s -c \"echo hi > %s\"", bkpinfo->nfs_user, tmp1);
     1250        mr_asprintf(tmp1,"%s/%s/.dummy.txt", bkpinfo->isodir,bkpinfo->netfs_remote_dir);
     1251        if ((bkpinfo->netfs_user) && (strstr(bkpinfo->netfs_proto,"nfs"))) {
     1252            mr_asprintf(tmp2, "su - %s -c \"echo hi > %s\"", bkpinfo->netfs_user, tmp1);
    12261253        } else {
    12271254            mr_asprintf(tmp2, "echo hi > %s", tmp1);
     
    12321259        if (i) {
    12331260            retval++;
    1234             log_to_screen(tmp2, "Are you sure directory '%s' exists in remote dir '%s'?\nIf so, do you have rights to write to it?\n", bkpinfo->nfs_remote_dir, bkpinfo->nfs_mount);
     1261            log_to_screen(tmp2, "Are you sure directory '%s' exists in remote dir '%s'?\nIf so, do you have rights to write to it?\n", bkpinfo->netfs_remote_dir, bkpinfo->netfs_mount);
    12351262        }
    12361263        unlink(tmp1);
Note: See TracChangeset for help on using the changeset viewer.