From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 4BFF574315 for ; Tue, 1 Jun 2021 14:13:54 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 22A72294A5 for ; Tue, 1 Jun 2021 14:13:54 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id B3F7329466 for ; Tue, 1 Jun 2021 14:13:52 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 8CE6B429B9 for ; Tue, 1 Jun 2021 14:13:52 +0200 (CEST) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Tue, 1 Jun 2021 14:13:48 +0200 Message-Id: <20210601121350.19919-3-d.csapak@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210601121350.19919-1-d.csapak@proxmox.com> References: <20210601121350.19919-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.041 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [datastore.rs] Subject: [pbs-devel] [PATCH proxmox-backup 2/4] api2/confif/datastore: add create datastore api call in a worker X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Jun 2021 12:13:54 -0000 so that longer running creates (e.g. a slow storage), does not run in a timeout and we can follow its creation Signed-off-by: Dominik Csapak --- src/api2/config/datastore.rs | 107 ++++++++++++++++++++++++++++++++++- www/window/DataStoreEdit.js | 3 +- 2 files changed, 108 insertions(+), 2 deletions(-) diff --git a/src/api2/config/datastore.rs b/src/api2/config/datastore.rs index 33e76b27..16ac030f 100644 --- a/src/api2/config/datastore.rs +++ b/src/api2/config/datastore.rs @@ -13,7 +13,7 @@ use crate::backup::*; use crate::config::cached_user_info::CachedUserInfo; use crate::config::datastore::{self, DataStoreConfig, DIR_NAME_SCHEMA}; use crate::config::acl::{PRIV_DATASTORE_ALLOCATE, PRIV_DATASTORE_AUDIT, PRIV_DATASTORE_MODIFY}; -use crate::server::jobstate; +use crate::server::{jobstate, WorkerTask}; #[api( input: { @@ -143,6 +143,110 @@ pub fn create_datastore(param: Value) -> Result<(), Error> { Ok(()) } +#[api( + protected: true, + input: { + properties: { + name: { + schema: DATASTORE_SCHEMA, + }, + path: { + schema: DIR_NAME_SCHEMA, + }, + comment: { + optional: true, + schema: SINGLE_LINE_COMMENT_SCHEMA, + }, + "notify-user": { + optional: true, + type: Userid, + }, + "notify": { + optional: true, + schema: DATASTORE_NOTIFY_STRING_SCHEMA, + }, + "gc-schedule": { + optional: true, + schema: GC_SCHEDULE_SCHEMA, + }, + "prune-schedule": { + optional: true, + schema: PRUNE_SCHEDULE_SCHEMA, + }, + "keep-last": { + optional: true, + schema: PRUNE_SCHEMA_KEEP_LAST, + }, + "keep-hourly": { + optional: true, + schema: PRUNE_SCHEMA_KEEP_HOURLY, + }, + "keep-daily": { + optional: true, + schema: PRUNE_SCHEMA_KEEP_DAILY, + }, + "keep-weekly": { + optional: true, + schema: PRUNE_SCHEMA_KEEP_WEEKLY, + }, + "keep-monthly": { + optional: true, + schema: PRUNE_SCHEMA_KEEP_MONTHLY, + }, + "keep-yearly": { + optional: true, + schema: PRUNE_SCHEMA_KEEP_YEARLY, + }, + }, + }, + access: { + permission: &Permission::Privilege(&["datastore"], PRIV_DATASTORE_ALLOCATE, false), + }, +)] +/// Create new datastore config. +pub fn create_datastore_worker( + param: Value, + rpcenv: &mut dyn RpcEnvironment, +) -> Result { + + let lock = open_file_locked(datastore::DATASTORE_CFG_LOCKFILE, std::time::Duration::new(10, 0), true)?; + + let datastore: datastore::DataStoreConfig = serde_json::from_value(param)?; + + let (mut config, _digest) = datastore::config()?; + + if config.sections.get(&datastore.name).is_some() { + bail!("datastore '{}' already exists.", datastore.name); + } + + let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; + + let upid_str = WorkerTask::new_thread( + "create-datastore", + Some(datastore.name.to_string()), + auth_id, + false, + move |_worker| { + let _lock = lock; // keep the lock + let path: PathBuf = datastore.path.clone().into(); + + let backup_user = crate::backup::backup_user()?; + let _store = ChunkStore::create(&datastore.name, path, backup_user.uid, backup_user.gid)?; + + config.set_data(&datastore.name, "datastore", &datastore)?; + + datastore::save_config(&config)?; + + jobstate::create_state_file("prune", &datastore.name)?; + jobstate::create_state_file("garbage_collection", &datastore.name)?; + + Ok(()) + }, + )?; + + Ok(upid_str) +} + #[api( input: { properties: { @@ -438,4 +542,5 @@ const ITEM_ROUTER: Router = Router::new() pub const ROUTER: Router = Router::new() .get(&API_METHOD_LIST_DATASTORES) .post(&API_METHOD_CREATE_DATASTORE) + .put(&API_METHOD_CREATE_DATASTORE_WORKER) .match_all("name", &ITEM_ROUTER); diff --git a/www/window/DataStoreEdit.js b/www/window/DataStoreEdit.js index c2b2809f..34ab74b9 100644 --- a/www/window/DataStoreEdit.js +++ b/www/window/DataStoreEdit.js @@ -75,6 +75,8 @@ Ext.define('PBS.DataStoreEdit', { isAdd: true, bodyPadding: 0, + method: 'PUT', + showProgress: true, cbindData: function(initialConfig) { var me = this; @@ -87,7 +89,6 @@ Ext.define('PBS.DataStoreEdit', { me.defaultFocus = 'textfield[name=comment]'; } me.url = name ? baseurl + '/' + name : baseurl; - me.method = name ? 'PUT' : 'POST'; me.scheduleValue = name ? null : 'daily'; me.autoLoad = !!name; return {}; -- 2.20.1