summaryrefslogtreecommitdiffstats
path: root/python
ModeNameSize
d---------examples150logstatsplain
-rw-r--r--modules.c1599logstatsplain
-rw-r--r--modules.h917logstatsplain
-rw-r--r--pyglue.c6873logstatsplain
d---------samba1026logstatsplain
d---------samba_external34logstatsplain
-rw-r--r--uuidmodule.c1497logstatsplain
-rw-r--r--wscript_build848logstatsplain
'n108' href='#n108'>108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413
/*
  Copyright (c) 2008, 2010 Gluster, Inc. <http://www.gluster.com>
  This file is part of GlusterFS.

  GlusterFS is free software; you can redistribute it and/or modify
  it under the terms of the GNU Affero General Public License as published
  by the Free Software Foundation; either version 3 of the License,
  or (at your option) any later version.

  GlusterFS is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Affero General Public License for more details.

  You should have received a copy of the GNU Affero General Public License
  along with this program.  If not, see
  <http://www.gnu.org/licenses/>.
*/

#include "libglusterfsclient.h"
#include "libglusterfsclient-internals.h"
#include <libgen.h>

#define LIBGLUSTERFS_CLIENT_DENTRY_LOC_PREPARE(_new_loc, _loc, _parent, \
                                               _resolved) do {          \
                size_t pathlen = 0;                                     \
                size_t resolvedlen = 0;                                 \
                char *path = NULL;                                      \
                int pad = 0;                                            \
                pathlen   = strlen (_loc->path) + 1;                    \
                path = CALLOC (1, pathlen);                             \
                _new_loc.parent =  _parent;                             \
                resolvedlen = strlen (_resolved);                       \
                strncpy (path, _resolved, resolvedlen);                 \
                if (resolvedlen == 1) /* only root resolved */          \
                        pad = 0;                                        \
                else {                                                  \
                        pad = 1;                                        \
                        path[resolvedlen] = '/';                        \
                }                                                       \
                strcpy_till (path + resolvedlen + pad,                  \
                             loc->path + resolvedlen + pad, '/');       \
                _new_loc.path = path;                                   \
                _new_loc.name = strrchr (path, '/');                    \
                if (_new_loc.name)                                      \
                        _new_loc.name++;                                \
        }while (0);


/* strcpy_till - copy @dname to @dest, until 'delim' is encountered in @dest
 * @dest - destination string
 * @dname - source string
 * @delim - delimiter character
 *
 * return - NULL is returned if '0' is encountered in @dname, otherwise returns
 *          a pointer to remaining string begining in @dest.
 */
static char *
strcpy_till (char *dest, const char *dname, char delim)
{
        char *src = NULL;
        int idx = 0;
        char *ret = NULL;

        src = (char *)dname;
        while (src[idx] && (src[idx] != delim)) {
                dest[idx] = src[idx];
                idx++;
        }

        dest[idx] = 0;

        if (src[idx] == 0)
                ret = NULL;
        else
                ret = &(src[idx]);

        return ret;
}

/* __libgf_client_path_to_parenti - derive parent inode for @path. if immediate 
 *                            parent is not available in the dentry cache, return nearest
 *                            available parent inode and set @reslv to the path of
 *                            the returned directory.
 *
 * @itable - inode table
 * @path   - path whose parent has to be looked up.
 * @reslv  - if immediate parent is not available, reslv will be set to path of the
 *           resolved parent.
 *
 * return - should never return NULL. should at least return '/' inode.
 */
static inode_t *
__libgf_client_path_to_parenti (libglusterfs_client_ctx_t *ctx,
                                inode_table_t *itable, const char *path,
                                char **reslv)
{
        char *resolved_till = NULL;
        char *strtokptr = NULL;
        char *component = NULL;
        char *next_component = NULL;
        char *pathdup = NULL;
        inode_t *curr = NULL;
        inode_t *parent = NULL;
        size_t pathlen = 0;
        loc_t rootloc = {0, };
        int ret = -1;

        pathlen = STRLEN_0 (path);
        resolved_till = CALLOC (1, pathlen);

        GF_VALIDATE_OR_GOTO("libglusterfsclient-dentry", resolved_till, out);
        pathdup = strdup (path);
        GF_VALIDATE_OR_GOTO("libglusterfsclient-dentry", pathdup, out);

        parent = inode_ref (itable->root);
        /* If the root inode's is outdated, send a revalidate on it.
         * A revalidate on root inode also reduces the window in which an
         * op will fail over distribute because the layout of the root
         * directory did not  get constructed when we sent the lookup on
         * root in glusterfs_init. That can happen when not all children of a
         * distribute volume were up at the time of glusterfs_init.
         */
        if (!libgf_is_iattr_cache_valid (ctx, parent, NULL,
                                        LIBGF_VALIDATE_LOOKUP)) {
                libgf_client_loc_fill (&rootloc, ctx, 1, 0, "/");
                ret = libgf_client_lookup (ctx, &rootloc, NULL, NULL, NULL);
                if (ret == -1) {
                        gf_log ("libglusterfsclient-dentry", GF_LOG_ERROR,
                                "Root inode revalidation failed");
                        inode_unref (parent);
                        parent = NULL;
                        goto out;
                }
                libgf_client_loc_wipe (&rootloc);
        }

        curr = NULL;

        component = strtok_r (pathdup, "/", &strtokptr);

        while (component) {
                curr = inode_search (itable, parent->ino, component);
                if (!curr) {
                        break;
                }
                if (!libgf_is_iattr_cache_valid (ctx, curr, NULL,
                                                LIBGF_VALIDATE_LOOKUP))
                        break;

                /* It is OK to append the component even if it is the       
                   last component in the path, because, if 'next_component'
                   returns NULL, @parent will remain the same and
                   @resolved_till will not be sent back               
                */
                strcat (resolved_till, "/");
                strcat (resolved_till, component);

                next_component = strtok_r (NULL, "/", &strtokptr);

                if (next_component) {
                        inode_unref (parent);
                        parent = curr;
                        curr = NULL;
                } else {
                        /* will break */
                        inode_unref (curr);
                }

                component = next_component;
        }

        if (resolved_till[0] == '\0') {
                strcat (resolved_till, "/");
        }

        free (pathdup);
        
        if (reslv) {
                *reslv = resolved_till;
        } else {
                FREE (resolved_till);
        }

out:
        return parent;
}

static inline void
libgf_client_update_resolved (const char *path, char *resolved)
{