~ubuntu-branches/ubuntu/precise/ceph/precise-proposed

« back to all changes in this revision

Viewing changes to src/rgw/rgw_fs.cc

  • Committer: Bazaar Package Importer
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2011-04-25 10:09:05 UTC
  • mfrom: (1.1.3 upstream) (0.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20110425100905-exm7dfvi2v5ick02
Tags: 0.27-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
84
84
  }
85
85
}
86
86
 
 
87
int RGWFS::obj_stat(string& bucket, string& obj, uint64_t *psize, time_t *pmtime)
 
88
{
 
89
  return -ENOTSUP;
 
90
}
 
91
 
87
92
int RGWFS::list_objects(string& id, string& bucket, int max, string& prefix, string& delim,
88
 
                       string& marker, vector<RGWObjEnt>& result, map<string, bool>& common_prefixes)
 
93
                       string& marker, vector<RGWObjEnt>& result, map<string, bool>& common_prefixes,
 
94
                       bool get_content_type)
89
95
{
90
96
  map<string, bool> dir_map;
91
97
  char path[BUF_SIZE];
227
233
  snprintf(buf, len, "%s/%s/%s", DIR_NAME, bucket.c_str(), obj.c_str());
228
234
  int fd;
229
235
 
230
 
  fd = open(buf, O_CREAT | O_WRONLY, 0755);
 
236
  int open_flags = O_CREAT | O_WRONLY;
 
237
  if (ofs == -1) {
 
238
    open_flags |= O_TRUNC;
 
239
    ofs = 0;
 
240
  }
 
241
 
 
242
  fd = open(buf, open_flags, 0755);
231
243
  if (fd < 0)
232
244
    return -errno;
233
245
 
234
246
  int r;
235
 
 
236
247
  r = lseek(fd, ofs, SEEK_SET);
237
248
  if (r < 0)
238
249
    goto done_err;
302
313
  return ret;
303
314
}
304
315
 
305
 
 
306
316
int RGWFS::delete_bucket(std::string& id, std::string& bucket)
307
317
{
308
318
  int len = strlen(DIR_NAME) + 1 + bucket.size() + 1;
470
480
  r = -ECANCELED;
471
481
  if (mod_ptr) {
472
482
    if (st.st_mtime < *mod_ptr) {
473
 
      err->num = "304";
474
 
      err->code = "NotModified";
 
483
      err->http_ret = 304;
 
484
      err->s3_code = "NotModified";
475
485
      goto done_err;
476
486
    }
477
487
  }
478
488
 
479
489
  if (unmod_ptr) {
480
490
    if (st.st_mtime >= *unmod_ptr) {
481
 
      err->num = "412";
482
 
      err->code = "PreconditionFailed";
 
491
      err->http_ret = 412;
 
492
      err->s3_code = "PreconditionFailed";
483
493
      goto done_err;
484
494
    }
485
495
  }
492
502
    if (if_match) {
493
503
      RGW_LOG(10) << "ETag: " << etag << " " << " If-Match: " << if_match << endl;
494
504
      if (strcmp(if_match, etag)) {
495
 
        err->num = "412";
496
 
        err->code = "PreconditionFailed";
 
505
        err->http_ret = 412;
 
506
        err->s3_code = "PreconditionFailed";
497
507
        goto done_err;
498
508
      }
499
509
    }
501
511
    if (if_nomatch) {
502
512
      RGW_LOG(10) << "ETag: " << etag << " " << " If_NoMatch: " << if_nomatch << endl;
503
513
      if (strcmp(if_nomatch, etag) == 0) {
504
 
        err->num = "412";
505
 
        err->code = "PreconditionFailed";
 
514
        err->http_ret = 412;
 
515
        err->s3_code = "PreconditionFailed";
506
516
        goto done_err;
507
517
      }
508
518
    }
537
547
  off_t pos = 0;
538
548
 
539
549
  while (pos < (off_t)len) {
540
 
    r = read(state->fd, (*data) + pos, len - pos);
 
550
    r = ::read(state->fd, (*data) + pos, len - pos);
541
551
    if (r > 0) {
542
552
      pos += r;
543
553
    } else {
577
587
  }
578
588
}
579
589
 
 
590
int RGWFS::read(std::string& bucket, std::string& oid, off_t ofs, size_t size, bufferlist& bl)
 
591
{
 
592
  int len = strlen(DIR_NAME) + 1 + bucket.size() + 1 + oid.size() + 1;
 
593
  char buf[len];
 
594
  int fd;
 
595
  int r = -EINVAL;
 
596
  bufferptr bp(size);
 
597
  char *data;
 
598
  size_t total = 0;
 
599
 
 
600
  snprintf(buf, len, "%s/%s/%s", DIR_NAME, bucket.c_str(), oid.c_str());
 
601
 
 
602
  fd = open(buf, O_RDONLY, 0755);
 
603
  if (fd < 0)
 
604
    return -errno;
 
605
 
 
606
#define READ_CHUNK (1024*1024)
 
607
  data = (char *)malloc(READ_CHUNK);
 
608
  if (!data) {
 
609
    r = -ENOMEM;
 
610
    goto done;
 
611
  }
 
612
 
 
613
  do {
 
614
    r = ::read(fd, data, READ_CHUNK);
 
615
    if (r < 0) {
 
616
      r = -errno;
 
617
      goto done;
 
618
    }
 
619
    bl.append(data, r);
 
620
    total += r;
 
621
  } while (r == READ_CHUNK);
 
622
  r = total;
 
623
 
 
624
done:
 
625
  free(data);
 
626
  close(fd);
 
627
  return r;
 
628
}
 
629